-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_functions
179 lines (156 loc) · 4.77 KB
/
.bash_functions
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/env bash
getBaseName() {
pwd | rev | cut -d '/' -f1 | rev;
}
have() { command -v "$1" >&/dev/null; }
createVenv() {
# dest="${PWD##*/}"
# You can run the function `getBaseName` and assign its output like this:
dest=$(getBaseName)
if python3 -m venv "$dest" ; then
cd "$dest"
source "./bin/activate"
[ ! -f "./requirements.txt" ] || pip install -r requirements.txt
echo You are now in new venv environment
else
echo "Failed to create 'venv' environment" >&2
fi;
}
createVenvNode() {
# dest="${PWD##*/}"
# You can run the function `getBaseName` and assign its output like this:
dest=$(getBaseName)
if python3 -m venv "$dest" ; then
cd "$dest"
source "./bin/activate"
# You can test the exit status of these commands with an if statement too
pip install nodeenv && nodeenv -p
echo You are now in new venv environment
else
echo "Failed to create 'venv' environment" >&2;
fi
}
ex() {
if [ -f "${1}" ] ; then
case "${1}" in
*.a) ar -xv "${1}" ;;
*.tgz) tar -xvzf "${1}" ;;
*.tar.gz) tar -xvzf "${1}" ;;
*.tar.bz2) tar -xvjf "${1}" ;;
*.tar.xz) tar -xvJf "${1}" ;;
*.bz2) bunzip2 "${1}" ;;
*.rar) unrar x -o- "${1}" ;;
*.gz) gunzip -vk "${1}" ;;
*.zip) unzip "${1}" ;;
*.7z) 7z x "${1}" ;;
*) echo "'${1}' unknow extension to extract!" ;;
esac
else
echo "'${1}' is not a valid file"
fi
}
if have xclip; then
alias psel='xclip -out -selection primary'
alias gsel='xclip -in -selection primary'
alias pclip='xclip -out -selection clipboard'
alias gclip='xclip -in -selection clipboard'
alias lssel='psel -target TARGETS'
alias lsclip='pclip -target TARGETS'
elif have xsel; then
alias psel='xsel -o -p -l /dev/null'
alias gsel='xsel -i -p -l /dev/null'
alias pclip='xsel -o -b -l /dev/null'
alias gclip='xsel -i -b -l /dev/null'
fi
clip() {
if (( $# )); then
echo -n "$*" | gclip
elif [[ ! -t 0 ]]; then
gclip
else
pclip
fi
}
alias tlsc='tlsg'
tlsg() {
if [[ $2 == -p ]]; then
set -- "$1" "${@:3}"
fi
local host=$1 port=${2:-443}
gnutls-cli "$host" -p "$port" "${@:3}"
}
tlso() {
if [[ $2 == -p ]]; then
set -- "$1" "${@:3}"
fi
local host=$1 port=${2:-443}
case $host in
*:*) local addr="[$host]";;
*) local addr="$host";;
esac
openssl s_client -connect "$addr:$port" -servername "$host" \
-verify_hostname "$host" -status -no_ign_eof -nocommands "${@:3}"
}
tlsb() {
if [[ $2 == -p ]]; then
set -- "$1" "--port=$3" "${@:4}"
fi
botan tls_client "$@"
}
tlscert() {
if [[ $2 == -p ]]; then
set -- "$1" "${@:3}"
fi
local host=$1 port=${2:-443}
if have gnutls-cli; then
tlsg "$host" "$port" --insecure --print-cert
elif have openssl; then
tlso "$host" "$port" -showcerts
fi < /dev/null
}
alias sslcert='tlscert'
lspkcs12() {
if [[ $1 == -g ]]; then
certtool --p12-info --inder "${@:2}"
elif [[ $1 == -n ]]; then
pk12util -l "${@:2}"
elif [[ $1 == -o ]]; then
openssl pkcs12 -info -nokeys -in "${@:2}"
fi
}
x509fp() {
local file=${1:-/dev/stdin}
openssl x509 -in "$file" -noout -fingerprint -sha256 | sed 's/.*=//' | tr A-F a-f
}
x509subj() {
local file=${1:-/dev/stdin}
openssl x509 -in "$file" -noout -subject -nameopt RFC2253 | sed 's/^subject=//'
}
x509subject() {
local file=${1:-/dev/stdin}
openssl x509 -in "$file" -noout -subject -issuer -nameopt multiline,dn_rev
}
# service management
if have systemctl && [[ -d /run/systemd/system ]]; then
start() { sudo systemctl start "$@"; _status "$@"; }
stop() { sudo systemctl stop "$@"; _status "$@"; }
restart() { sudo systemctl restart "$@"; _status "$@"; }
reload() { sudo systemctl reload "$@"; _status "$@"; }
status() { SYSTEMD_PAGER='cat' systemctl status -a "$@"; }
_status() { sudo SYSTEMD_PAGER='cat' systemctl status -a -n0 "$@"; }
alias enable='sudo systemctl enable'
alias disable='sudo systemctl disable'
alias list='systemctl list-units -t path,service,socket --no-legend'
alias userctl='systemctl --user'
alias u='systemctl --user'
alias y='systemctl'
ustart() { userctl start "$@"; userctl status -a "$@"; }
ustop() { userctl stop "$@"; userctl status -a "$@"; }
urestart() { userctl restart "$@"; userctl status -a "$@"; }
ureload() { userctl reload "$@"; userctl status -a "$@"; }
alias ulist='userctl list-units -t path,service,socket --no-legend'
alias lcstatus='loginctl session-status $XDG_SESSION_ID'
alias tsd='tree /etc/systemd/system'
cgls() { SYSTEMD_PAGER='cat' systemd-cgls "$@"; }
usls() { cgls "/user.slice/user-$UID.slice/$*"; }
fi