-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.shell_funcs
199 lines (168 loc) · 3.6 KB
/
.shell_funcs
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# vim: syntax=sh:
# _____ _ _ _ _ ____ _____ ___ ___ _ _ ____
# | ___| | | | \ | |/ ___|_ _|_ _/ _ \| \ | / ___|
# | |_ | | | | \| | | | | | | | | | \| \___ \
# | _| | |_| | |\ | |___ | | | | |_| | |\ |___) |
# |_| \___/|_| \_|\____| |_| |___\___/|_| \_|____/
#
#ssh-blast() {
#
# local sshretval
#
# while [ "$sshretval" != "0" ] ; do
# ssh -o "ConnectTimeout=1" \
# -o "BatchMode=yes" \
# -o "StrictHostKeyChecking=no" \
# -o "UserKnownHostsFile=/dev/null"\
# -o "PreferredAuthentications=publickey"\
# $@
#
# let sshretval="$?"
# done
#}
#
#
#for i in sha512 sha256 sha1 md5; do
# eval "ssl-cert-${i}() {
# openssl x509 -noout -fingerprint -${i} -in \$1
# }"
#done; unset i
#
#ssl-cert-fingerprints() {
# local i
# if [[ -z $1 ]] ; then
# printf 'usage: ssl-cert-fingerprints <file>\n'
# return 1
# fi
# for i in sha512 sha256 sha1 md5 ; do
# ssl-cert-$i $1;
# done
#}
#
#ssl-cert-info() {
# if [[ -z $1 ]] ; then
# printf 'usage: ssl-cert-info <file>\n'
# return 1
# fi
# openssl x509 -noout -text -in $1
# ssl-cert-fingerprints $1
#}
#
set_title () {
if [ "$0" = "bash" ] || [ "$0" = "zsh" ] ; then
echo -en "\033]0;${@}\007"
else
echo -n "\033]0;${@}\007"
fi
}
cdt() {
cd "$(mktemp -d)"
pwd
}
# contains(string, substring)
#
# Returns 0 if the specified string contains the specified substring,
# otherwise returns 1.
contains() {
string="$1"
substring="$2"
if test "${string#*$substring}" != "$string"
then
return 0 # $substring is in $string
else
return 1 # $substring is not in $string
fi
}
# note taking
n() {
$EDITOR ~/notes/"$*".txt
}
nls() {
ls -c ~/notes/ | grep "$*"
}
list_fonts() {
fc-scan --format "-%{foundry}-%{family}\n" `pwd`
}
# this is primarily for daemons and programs that get started in xinitrc
run_util() {
$@ >/dev/null 2>$HOME/utils.log &
}
run_bg() {
$@ >/dev/null 2>&1 &
}
genpass() {
LC_CTYPE=C tr -cd '[:alnum:]' < /dev/urandom | fold -w16 | head -n1
}
ps_memavg() {
ps -ylC $1 --sort:rss | awk '{sum+=$8; ++n} END {print "Total Memory = "sum/1024" MB ("n" procs)";print "Avg per process = "sum/n/1024" MB"}'
}
tmux_escape_printf() {
printf "\033Ptmux;\033%s\033\\" $@
}
iterm2_set_badge() {
if contains "$IS_THIS_ITERM2" "TRUE" ; then
printf "\033]1337;SetBadgeFormat=%s\a" $(echo -n "$@" | base64)
return 0
elif contains "$IS_THIS_ITERM2" "TMUX" ; then
tmux_escape_printf `printf "\033]1337;SetBadgeFormat=%s\a" $(echo -n "$@" | base64)`
return 0
else
return 1
fi
}
home_print() {
lpr -P dellprinter5210 -h $@
}
# validate an ip
valid_ip() {
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
straceall() {
strace $(pidof "${1}" | sed 's/\([0-9]*\)/-p \1/g')
}
_filelooper() {
local file="$1"
shift
cat<<-EOF
while IFS= read -r line ; do $* \$line ; done<$file
EOF
}
filelooper() {
local runner="$( _filelooper $*)"
echo -e "will run: \n $runner" >&2
local timeout=3
while test $timeout -gt 0 ; do
echo -e "Will run in $timeout seconds. hit CTRL-C to cancel...\n" >&2
sleep 1
let timeout=$((timeout - 1))
done
#eval "`/bin/echo \'${runner}\'`"
eval "${runner}"
}
_df_echoerr() {
printf '%b\n\r' "$@" >&2 || true
return 0
}
_df_alert() {
printf '\a\n\r\t\t\t %b \n\r' "$@" >&2 || true
return 0
}
_df_error() {
printf '\a\n\r\tdotfiles init error: %b \n\r' "$@" >&2 || true
return 0
}
_df_panic() {
printf '\a\n\r\tdotfiles init panic: %b \n\r' "$@" >&2 || true
return 127
}