-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions
More file actions
76 lines (63 loc) · 1.44 KB
/
functions
File metadata and controls
76 lines (63 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#
# Crypto
#
function sha1() {
if [[ -f $1 ]]; then
sha1sum $1 | sed -e "s/$1/$1 (file)/g"
else
checksum=$(echo -n $1 | openssl sha1 | sed -e "s/(stdin)= //")
echo "$checksum \"$1\" (string)"
fi
}
function sha256() {
if [[ -f $1 ]]; then
sha256sum $1 | sed -e "s/$1/$1 (file)/g"
else
checksum=$(echo -n $1 | openssl sha256 | sed -e "s/(stdin)= //")
echo "$checksum \"$1\" (string)"
fi
}
function sha512() {
if [[ -f $1 ]]; then
sha512sum $1 | sed -e "s/$1/$1 (file)/g"
else
checksum=$(echo -n $1 | openssl sha512 | sed -e "s/(stdin)= //")
echo "$checksum \"$1\" (string)"
fi
}
#
# Docker
#
function dsh() {
docker exec -it $1 /bin/bash
}
#
# Files
#
# Counts the files.
function files() {
ls $1 | wc -l
}
#
# Hardware
#
# https://unix.stackexchange.com/a/119170/173034
function disk() {
df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
}
#
# Git
#
function ghrepo() {
local remote_url=$(git config --get remote.origin.url 2>/dev/null)
if [ -z "$remote_url" ]; then
echo "Error: Could not find remote 'origin' URL. Are you in a Git repository?" >&2
return 1
fi
if [[ "$remote_url" =~ ^git@ ]]; then
https_url=$(echo "$remote_url" | sed -E 's/^git@//' | sed -E 's/:/\//' | sed -E 's/^/https:\/\//')
xdg-open "$https_url"
else
xdg-open "$remote_url"
fi
}