-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_aliases
329 lines (300 loc) · 9.36 KB
/
bash_aliases
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/bin/bash
# interactively remove file -- good for beginners
alias rm='rm -i'
alias ?='man man'
alias ls='ls -CF'
alias list='more -l'
alias wa='who -a'
alias h='history'
alias lo='logout'
if hash gnome-open 2>/dev/null; then
alias open='gnome-open'
fi
if [ -x /usr/bin/vim ]; then
alias vi=vim
fi
if hash hub 2>/dev/null; then
alias git='hub'
fi
gitdelbranch () {
if [ -z $1 ]; then
echo "usage: $0 branchname"
return 1
fi
git branch -d $1
git push origin --delete $1
}
# Use the Berkeley Mail program
if hash Mail 2>/dev/null; then
alias mail='Mail'
fi
alias al='ls -al'
alias su='su -'
# logout alias
alias bye='clear; logout'
# Strip all comments from a file and display it
alias stripcomments="sed 's/#.*$//;/^[ ]*$/d' $*"
# Monit summary failed services
alias monitbad="sudo monit summary | egrep -v 'Accessible|Running'"
# X11 Auth update
#rxauth() { xauth extract - `uname -n`:0 | rsh $* xauth merge - }
# Setup root xauth
rootxauth () {
export XAUTHORITY=$HOME/.Xauthority
chmod a+r $XAUTHORITY
}
# Xterm aliases
settitle () {
echo -n -e "\033]2;$*\007"
}
seticonname () {
echo -n -e "\033]1;$*\007"
}
# WOL hosts
alias wake_dream="sudo ether-wake 00:60:08:20:CF:34"
alias wake_sandman="sudo ether-wake 60:33:4b:29:ba:5b"
alias wake_kodi="sudo ether-wake c4:54:44:77:10:d9"
# Compiz startup -- update in /usr/bin/compiz-gtk
function runCompiz() {
gtk-window-decorator &
# exec compiz –ignore-desktop-hints glib gconf gnomecompat $@
exec compiz --replace --sm-disable --indirect-rendering --ignore-desktop-hin
ts ccp glib gconf gnomecompat $@ &
# exec compiz --replace --sm-disable --loose-binding --ignore-desktop-hints c
cp glib gconf gnomecompat $@ &
}
# Configure chef dev environment
alias chefdk='eval "$(chef shell-init bash)"'
# JSON
function jsonlint() {
if [ -f "$1" ]; then
python -mjson.tool < $1 > /dev/null
else
python -mjson.tool > /dev/null
fi
}
function jsonpp() {
if [ -f "$1" ]; then
python -mjson.tool < $1
else
python -mjson.tool
fi
}
# SSH forwarding
endforward() {
pids=`ps -efww| egrep 'ssh.*morpheus-forward' | egrep -v grep | awk '{print $2}'`
if [ -n "$pids" ]; then
kill $pids
fi
}
alias homeforward='endforward && ssh -f -N morpheus-forward && echo "Proxy started"'
alias homeproxyforward='endforward && ssh -f -N morpheus-forward-proxy && echo "Proxy started"'
fixssh() {
if [ -z "$1" ]; then
echo "usage: fixssh [user@]host"
fi
# deal with user@host
IFS=@ read sshuser sshhost <<< "$1"
if [ -z "$sshhost" ]; then
sshhost=$sshuser
sshuser=''
fi
sshfqdn=`host $sshhost | awk '{print $sshhost}'`
sshaddr=`host $sshhost | awk '{print $NF}'`
#sshhost=`nslookup $1 | sed -n '/Name:/,/Address:/p' | awk '{print $2}'`
for sshhostall in $sshhost $sshfqdn $sshaddr; do
exists=`ssh-keygen -F $sshhostall | wc -c`
if [ "$exists" != 0 ]; then
echo $sshhostall | sed 's/,/ /g' | xargs -n1 ssh-keygen -R
fi
done
if [ -n "$sshuser" ]; then
ssh $sshuser@$sshfqdn
else
ssh $sshfqdn
fi
}
alias sshnokey='ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no'
sshinstallkeys() {
if [ -z "$1" ]; then
echo "usage: sshinstallkeys hostname"
else
if [ -x '/usr/bin/ssh-copy-id' ]; then
echo "$1..." && ssh-copy-id -oConnectionAttempts=1 -oConnectTimeout=10 -oStrictHostKeyChecking=no $1
else
echo "$1..." && cat ~/.ssh/id_ed25519.pub | ssh -oConnectionAttempts=1 -oConnectTimeout=10 -oStrictHostKeyChecking=no $1 "umask 077 && mkdir ~/.ssh 2>/dev/null; cat >> ~/.ssh/authorized_keys"
fi
fi
}
if hash xxdiff 2>/dev/null; then
alias xdiff="xxdiff"
fi
# Larger window for rdesktop
#alias rdesktop='rdesktop -g1152x768'
alias rdesktop='rdesktop -a16 -g1280x1024'
# VNC is vinagre
if hash vinagre 2>/dev/null; then
alias vncviewer="vinagre"
fi
# Start/stop remove VNC
# General host start/stop
vncstart () {
ssh -f -n $1 x11vnc -display :0 -many -bg && sleep 5 && vncviewer -geometry +0+0 $1
}
vncstop () {
ssh -f -n $1 killall x11vnc
}
# Remote connection aliasts
alias morpheus-con='ssh -f -L5909:morpheus-con:5900 morpheus.lapseofthought.com sleep 10; vncviewer localhost:9'
alias destiny-con='ssh -f -L5908:destiny-con:5900 voip.lapseofthought.com sleep 10; vncviewer localhost:8'
# Forward an SSH port for thye specified time
# usage sshforward host port [time]
# por tmay eitehr be a single port or a port:host:port triplet
sshportforward() {
host=$1
port=$2
time=$3
if `echo $port | grep ':' > /dev/null 2>&1`; then # If port has a colon
:
else
port=$port:$host:$port
fi
if [ -n "$time" ]; then
ssh -f -L$port $host sleep $time; echo "Connection will be available for $time seconds...";
else
ssh -f -N -L$port $host
fi
}
sshstop() {
pid=`ps -efww | grep $1 | egrep -v grep | awk '{print $2}'`
if [ -n "$pid" ]; then
kill $pid
fi
}
alias headphones='sshportforward xbmc.lapseofthought.com 8181 3600 && echo "Use headphones-stop to end it" && firefox http://localhost:8181/'
alias lazylibrarian='sshportforward xbmc.lapseofthought.com 5299 3600 && echo "Use lazylibrarian-stop to end it" && firefox http://localhost:5299/'
alias maraschino='sshportforward xbmc.lapseofthought.com 7000 3600 && echo "Use maraschino-stop to end it" && firefox http://localhost:7000/'
alias pytivo='sshportforward xbmc.lapseofthought.com 9032 3600 && echo "Use pytivo-stop to end it" && firefox http://localhost:9032/'
alias sabnzbd='sshportforward xbmc.lapseofthought.com 8085 3600 && echo "Use sabnzbd-stop to end it" && firefox http://localhost:8085/'
alias sickbeard='sshportforward xbmc.lapseofthought.com 8081 3600 && echo "Use sickbeard-stop to end it" && firefox http://localhost:8081/'
alias subsonic='sshportforward xbmc.lapseofthought.com 4040 3600 && echo "Use subsonic-stop to end it" && firefox http://localhost:4040/'
alias utorrent='sshportforward xbmc.lapseofthought.com 8082 3600 && echo "Use utorrent-stop to end it" && firefox http://localhost:8082/'
alias xbmc='sshportforward xbmc.lapseofthought.com 8080 3600 && echo "Use xbmc-stop to end it" && firefox http://localhost:8080/'
alias headphones-stop='sshstop 8181:xbmc.lapseofthought.com:8181'
alias lazylibrarian-stop='sshstop 5299:xbmc.lapseofthought.com:5299'
alias maraschino-stop='sshstop 7000:xbmc.lapseofthought.com:7000'
alias pytivo-stop='sshstop 9032:xbmc.lapseofthought.com:9032'
alias sabnzbd-stop='sshstop 8085:xbmc.lapseofthought.com:8085'
alias sickbeard-stop='sshstop 8081:xbmc.lapseofthought.com:8081'
alias subsonic-stop='sshstop 4040:xbmc.lapseofthought.com:4040'
alias utorrent-stop='sshstop 8082:xbmc.lapseofthought.com:8082'
alias xbmc-stop='sshstop 8080:xbmc.lapseofthought.com:8080'
# iTerm2
# Change iterm2 profile. Usage it2prof ProfileName (case sensitive)
it2prof() {
echo -e "\033]50;SetProfile=$1\a"
}
alias it2profdark='it2prof "Solarized Dark"'
alias it2proflight='it2prof "Solarized Light"'
alias it2pd='it2prof "Solarized Dark"'
alias it2pl='it2prof "Solarized Light"'
# If running iTerm2, enable tmux integration
if [ "$TERM_PROGRAM" == "iTerm.app" ]; then
export ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX=YES
#alias tmux='tmux -CC new'
fi
# Remote tmux
rtmux() {
usage() {
echo "usage: rtumx hostname [session]"
return 1
}
if [ -z "$1" ]; then
usage
else
sessargs=""
if [ -n "$2" ]; then
sessargs="-s $2"
fi
# Support for iterm integration
if [ "$TERM_PROGRAM" == "iTerm.app" ]; then
#ssh -t $1 "tmux -CC new -A $sessargs"
ssh -t $1 "tmux new -A $sessargs"
else
ssh -t $1 "tmux new -A $sessargs"
fi
fi
}
alias ta='tmux attach -t'
alias tad='tmux attach -d -t'
alias ts='tmux new-session -s'
alias tl='tmux list-sessions'
alias tksv='tmux kill-server'
alias tkss='tmux kill-session -t'
tms() { # New session, attach to existing session if the named one exists
usage() {
echo "usage: tns [session-name [window-name]]"
return 1
}
if [ -n "$3" ]; then
usage
return 1
fi
args=""
if [ -n "$1" ]; then
args="-As ${1}"
if [ -n "$2" ]; then
args="${args} -n ${2}"
fi
fi
tmux new-session ${args}
}
tmw() { # New window, may use existing session or create named window
usage() {
echo "usage: tnw [session-name [window-name]]"
return 1
}
if [ -n "$3" ]; then
usage
fi
args=""
if [ -n "$1" ]; then
args="-t ${1}:"
if [ -n "$2" ]; then
args="${args} -n ${2}"
fi
fi
tmux new-window ${args}
}
alias tml='tmux list-sessions'
# Mac
alias checktemp="sudo powermetrics | egrep -i 'temperature|therm|fan'"
alias checksmc="sudo powermetrics | sed -n '/SMC sensors/,/GPU2/p'"
alias checkdisk="sudo powermetrics | sed -n '/Network activity/,/in:/p'"
alias checknetwork="sudo powermetrics | sed -n '/Disk activity/,/write:/p'"
alias watchistats="watch --color istats"
# Postfix
alias flushmd="mailq | grep MAILER-DAEMON | awk '{print $1}'| xargs -n1 sudo postsuper -d"
learnspamham () {
sa-learn --no-sync --spam ~/Maildir/.spam/{cur,new}
sa-learn --no-sync --ham ~/Maildir/{cur,new}
}
# SSL utils
checkcert() {
usage() {
echo "usage: checkcert host:port [protocol]"
return 1
}
if [ -z "$1" ]; then
usage
fi
args=""
# Split arg 1 into host and port
IFS=':' read -a hostarg <<< $1
host=${hostarg[0]}
port=${hostarg[1]:-443}
if [ -n "$2" ]; then
args="-starttls $2"
fi
openssl s_client -servername $host -connect $host:$port ${args} < /dev/null | openssl x509 -noout -subject -alias -serial -dates
}