-
Notifications
You must be signed in to change notification settings - Fork 2
/
.aliases
467 lines (371 loc) · 14.7 KB
/
.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#!/usr/bin/env bash
# Aliases
# vim: syntax=sh
OS="$(uname)"
export OS
# Misc
alias vi='vim'
if command -v nvim &>/dev/null; then
alias vi='nvim'
alias vim='nvim'
fi
alias ri='ri -f ansi'
command -v colordiff &>/dev/null && alias diff='colordiff'
alias takeover='tmux detach -a'
alias ag='ag --smart-case --pager="less -MIRFX"'
# Git
if command -v hub &>/dev/null; then
alias git=hub
# https://github.com/github/hub/issues/1792#issuecomment-518227676
alias __git=hub
fi
alias ga='git add --patch'
alias gbd='git branch -d'
alias gc='git commit -v'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcp='git cherry-pick'
alias gd='git diff'
alias gp='git push'
alias gpo='git push origin'
alias gpu='git push --set-upstream'
alias gpuo='git push --set-upstream origin'
alias gr='git remote'
alias grv='git remote -v'
alias gst='git status'
alias gd='git diff'
alias glglm='git log --before=$(date "+%Y-%m-01") --after=$(date -d"1 month ago" "+%Y-%m-01") \
--author="$(git config user.name)" --reverse --pretty=format:"%cd - %h - %s" --date=short --no-merges'
alias glgcm='git log --before=$(date -d"+ 1 month" "+%Y-%m-01") --after=$(date "+%Y-%m-01") \
--author="$(git config user.name)" --reverse --pretty=format:"%cd - %h - %s" --date=short'
alias glgt='git log --since="yesterday" --author="$(git config user.name)" --pretty=format:"%cd - %h - %s" \
--date=short --no-merges'
alias reflog='git reflog --pretty=raw | tig --pretty=raw'
alias merged='git branch --merged master | grep -v master | xargs -n 1 git branch -d && git fetch --prune'
alias gsw='git switch'
alias gswc='git switch -c'
alias grs='git restore'
alias grss='git restore --source'
# Some aliases to avoid making mistakes
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ln='ln -i'
# shortcuts
alias c='clear'
alias x='exit'
alias q='exit'
alias h='history'
alias j='jobs -l'
# grep
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
# Quick HTTP server
alias serve='ruby -run -e httpd . -p 8080'
alias pserve='python -m SimpleHTTPServer'
# Time
alias now='date +"%T"'
alias nowtime='now'
alias nowdate='date +"%d-%m-%Y"'
# Copilot
alias copilot='gh copilot'
alias gcs='gh copilot suggest'
alias gce='gh copilot explain'
# Can I haz `timeout` ?
hash gtimeout &>/dev/null && alias timeout='gtimeout'
# Override ls alias from common-aliases plugin
if command -v eza &>/dev/null; then
alias l='eza -lbF --git'
alias la='eza -lbhHigUmuSa --time-style=long-iso --git --color-scale'
alias ll='ls -lah'
alias ls='eza'
alias lt='eza --tree --level=2'
else
alias l='ls -lFh'
alias la='ls -lAFh'
alias ll='ls -lah'
alias lr='ls -tRFh'
alias ls='ls -G'
alias lt='ls -ltFh'
fi
if command -v btm &>/dev/null; then
alias htop='btm'
alias top='btm'
fi
# Delete file securely
alias shred='shred -n 200 -z -u'
# Shuf
if command -v gshuf &>/dev/null; then
alias shuf='gshuf'
fi
# clear
alias c='clear'
alias cls='clear'
alias q='exit'
# watch alias expend
alias watch='watch '
# tree
if [ ! -x "$(command -v tree &>/dev/null)" ]; then
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
fi
# Cuz IMADUMMY
if command -v mysql &>/dev/null; then
alias mysql='mysql --i-am-a-dummy'
mysql-fast-shutdown() {
mysql -e 'set global innodb_max_dirty_pages_pct = 0;'
service mysql stop
}
mysql_genocide() {
local sql='/tmp/kill.sql'
[[ -f "${sql}" ]] && rm -f "${sql}"
local user=$1
if [[ -z $user ]]; then
echo 'Please specify the user name as first argument'
exit 1
fi
local queries_to_kill="SELECT concat('KILL ',id,';')
FROM information_schema.processlist
WHERE user='${user}'
INTO OUTFILE '${sql}';
"
mysql -e "$queries_to_kill" && mysql -e "source ${sql};"
}
alias purge-binary-logs="mysql -e 'PURGE BINARY LOGS BEFORE DATE_SUB(NOW(), INTERVAL 1 DAY);'"
fi
# CAN I HAZ ?
alias please='sudo'
# passing alias to sudo
alias sudo='sudo '
# set goaccess config file
alias goaccess='goaccess -p ~/.goaccessrc '
# ssht/sshrc
alias yolossh='ssh -F /dev/null -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
alias ssht=sshrc
command -v compdef &>/dev/null && compdef ssht=ssh && compdef sshrc=ssh
# Secure ssh-agent usage
alias ssh-add='ssh-add -c -t 4h'
# Reload the shell (i.e. invoke as a login shell)
alias reload="exec $SHELL -l"
# make
if command -v caffeinate &>/dev/null; then
alias make='caffeinate make'
fi
# kubectl
if command -v kubectl &>/dev/null; then
alias k=kubectl
complete -F __start_kubectl k
alias netshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash'
fi
# akamai
alias akamai='docker run -it -v ${HOME}/.config/akamai/.edgerc:/root/.edgerc:ro akamai/shell:latest akamai'
# Pandoc
function pandoc() {
docker run --rm --name pandoc -v "${PWD}:/pandoc" dalibo/pandocker "$@"
}
# Mass updating DNS zone serial numbers
function massdnsserialupdate() {
sed -i "s,20[0-9][0-9]\{7\},$(date +%Y%m%d00),g" db.*
}
function tea() {
local STEEP_TIME=${STEEP_TIME:=180}
[[ "$STEEP_TIME" != [0-9]* ]] && exit 1
sleep "$STEEP_TIME"
terminal-notifier \
-title '🍵 Tea Club' \
-message 'Your tea is ready!' \
-appIcon 'https://www.emojibase.com/resources/img/emojis/apple/x2615.png.pagespeed.ic.fUhSj-YPGK.png'
}
function netdata() {
port=$(shuf -i 2000-65000 -n 1)
(sleep 2 && open "http://127.0.0.1:${port}" &) >/dev/null
ssh -N -L "${port}:127.0.0.1:19999" "${@}"
}
# Nomad
if command -v nomad &>/dev/null; then
nomad-status() {
local job
unset FZF_DEFAULT_OPTS
job=$(nomad job status | tail +2 | fzf -1 -q "$1" | awk '{ print $1 }')
[[ -n "$job" ]] && nomad job status "$job"
}
nomad-log() {
local allocation job
unset FZF_DEFAULT_OPTS
job=$(nomad job status | tail +2 | fzf -1 -q "$1" | awk '{ print $1 }')
allocation=$(nomad job status "$job" | awk '/^Allocations/,EOF' | tail +3 | fzf -1 -q "$1" | awk '{ print $1 }')
task=$(nomad alloc status --short "$allocation" | awk '/^Tasks/,EOF' | tail +3 | fzf -1 | awk '{ print $1 }')
[ -n "$allocation" ] && nomad alloc logs -tail -f -n 100 "$allocation" "$task"
}
nomad-exec() {
local allocation job task
unset FZF_DEFAULT_OPTS
job=$(nomad job status | tail +2 | fzf -1 | awk '{ print $1 }')
allocation=$(nomad job status "$job" | awk '/^Allocations/,EOF' | tail +3 | fzf -1 | awk '{ print $1 }')
task=$(nomad alloc status --short "$allocation" | awk '/^Tasks/,EOF' | tail +3 | fzf -1 | awk '{ print $1 }')
[ -n "$allocation" ] && nomad alloc exec -i -t -task "$task" "$allocation" "$@"
}
fi
command -v compdef &>/dev/null && compdef netdata=ssh
# Aliases for OSx
# See https://github.com/mathiasbynens/dotfiles/blob/master/.aliases
if [[ $OS == 'Darwin' ]]; then
# Stopwatch
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'
# Get OS X Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update'
# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ipconfig getifaddr en0"
alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
# Flush Directory Service cache
alias flush='dscacheutil -flushcache && killall -HUP mDNSResponder'
# Clean up LaunchServices to remove duplicates in the “Open With” menu
alias lscleanup='/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder'
# Empty the Trash on all mounted volumes and the main HDD.
# Also, clear Apple’s System Logs to improve shell startup speed.
# Finally, clear download history from quarantine. https://mths.be/bum
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl; sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'"
# Show/hide hidden files in Finder
alias show='defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder'
alias hide='defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder'
# Hide/show all desktop icons (useful when presenting)
alias hidedesktop='defaults write com.apple.finder CreateDesktop -bool false && killall Finder'
alias showdesktop='defaults write com.apple.finder CreateDesktop -bool true && killall Finder'
# Merge PDF files
# Usage: `mergepdf -o output.pdf input{1,2,3}.pdf`
alias mergepdf='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py'
# Disable/Enable Spotlight
alias spotoff='sudo mdutil -a -i off'
alias spoton='sudo mdutil -a -i on'
# PlistBuddy alias, because sometimes `defaults` just doesn’t cut it
alias plistbuddy='/usr/libexec/PlistBuddy'
# Ring the terminal bell, and put a badge on Terminal.app’s Dock icon
# (useful when executing time-consuming commands)
alias badge='tput bel'
# Stuff I never really use but cannot delete either because of http://xkcd.com/530/
alias stfu="osascript -e 'set volume output muted true'"
alias pumpitup="osascript -e 'set volume 7'"
# Kill all the tabs in Chrome to free up memory
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"
# Lock the screen (when going AFK)
alias afk="pmset displaysleepnow && osascript -e 'set volume output muted true'"
# Manual backup
alias backup='tmutil startbackup --block && tmutil startbackup --block;'
# Mute/Unmute the system volume. Plays nice with all other volume settings.
alias mute="osascript -e 'set volume output muted true'"
alias unmute="osascript -e 'set volume output muted false'"
# Tor new identity
alias tornewidentity='docker kill --signal=HUP tor'
# Secure ssh-agent usage
alias ssh-add='ssh-add -t 4h'
# Lock/Unlock directory or file
function lock() {
find "$@" -type d | gxargs -d '\n' -n 1 chmod 0500
find "$@" -type f | gxargs -d '\n' -n 1 chmod 0400
chflags -R uchg "$@"
}
function unlock() {
chflags -R nouchg "$@"
find "$@" -type d | gxargs -d '\n' -n 1 chmod 0700
find "$@" -type f | gxargs -d '\n' -n 1 chmod 0600
}
alias awk='gawk'
alias date='gdate'
alias find='gfind'
alias make='gmake'
alias sed='gsed'
fi
# Aliases for Linux, Ops.
if [[ $OS == 'Linux' ]]; then
# safety, override
alias rm='rm -i --preserve-root'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
# can i haz color
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias ll='ls -lah'
alias la='ls -A'
alias l='ls -lAh'
# Find large files and directories
alias fat='du -a | sort -n -r | head -n 20'
# Show open ports
alias ports='netstat -tulanp'
# Memory
alias meminfo='free -m -l -t'
# Get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
# Get top process eating cpu
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
# Count all opened files by all process
alias count_opened_files='lsof | wc -l'
# Get maximum open files count allowed
alias max_open_files='cat /proc/sys/fs/file-max'
# Flush swap
alias swapoffon='nohup bash -c "swapoff -a; swapon -a" &>/dev/null'
# Yolo
alias dropcache='sync && echo 3 > /proc/sys/vm/drop_caches'
# iptables
alias ipt='iptables'
alias iptlist='iptables -L -n -v --line-numbers'
alias iptlistin='iptables -L INPUT -n -v --line-numbers'
alias iptlistout='iptables -L OUTPUT -n -v --line-numbers'
alias iptlistfw='iptables -L FORWARD -n -v --line-numbers'
alias firewall='iptlist'
alias ban='iptables -I INPUT -j DROP -s'
alias unban='iptables -D INPUT -j DROP -s'
alias banin='iptables -I INPUT -j DROP -s'
alias unbanin='iptables -D INPUT -j DROP -s'
alias banout='iptables -I OUTPUT -j DROP -s'
alias unbanout='iptables -D OUTPUT -j DROP -s'
alias listbans='iptables -L -v -n | grep -e Chain -e DROP'
# Log
if command -v ccze &>/dev/null; then
alias syslog='sudo tail -f /var/log/syslog | ccze'
else
alias syslog='sudo tail -f /var/log/syslog'
fi
alias tf='sudo tail -f'
# Memcached
if command -v memcached &>/dev/null; then
memcached_ip=$(grep 'IP' -A1 /etc/memcached.conf | tail -n 1 | cut -d' ' -f2)
memcached_port=$(grep 'port' -A1 /etc/memcached.conf | tail -n 1 | cut -d' ' -f2)
alias mctop="tcpdump -i eth1 -s 65535 -A -ttt port 11211| cut -c 9- | grep -i '^get\|set'"
alias mcstats="watch -n 1 '(echo stats ; echo quit ) | nc -q2 $memcached_ip $memcached_port'"
alias mcflush="echo 'flush_all' | nc -q 2 $memcached_ip $memcached_port"
fi
# Nginx/Apache access log parsing
# https://rtcamp.com/tutorials/nginx/log-parsing/
# http://eddmann.com/posts/processing-apache-and-nginx-access-logs/
alias http_access="cat *access.log | cut -d '\"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -rn"
alias http_404="cat *access.log | awk '($9 ~ /404/)' | awk '{ print $7 }' | sort | uniq -c | sort -rn"
alias http_ua="cat *access.log | awk -F\" '{ print $6 }' | sort | uniq -c | sort -frn | head -n 25"
alias http_requests_by_ip="cat *access.log | awk '{ print $1 }' | sort | uniq -c | sort -rn | head -n 25"
alias http_count_visits="cat *access.log | awk '{ print $1 }' | sort | uniq -c | wc -l"
alias http_count_visits_by_day="cat *access.log | grep $(date '+%e/%b/%G') | awk '{ print $1 }' | sort | uniq -c | wc -l"
alias http_count_visits_by_month="cat *access.log | grep $(date '+%b/%G') | awk '{ print $1 }' | sort | uniq -c | wc -l"
alias http_popular_urls="cat *access.log | awk '{ print $7 }' | sort | uniq -c | sort -rn | head -n 25"
# services specific
if command -v nginx &>/dev/null; then
alias nginxtest='nginx -t'
alias nginxreload='nginxtest && service nginx reload'
fi
if command -v apache2ctl &>/dev/null; then
alias apachetest='apache2ctl -t'
alias apachereload='apachetest && service apache2 reload'
fi
if command -v php5-fpm &>/dev/null; then
alias php5fpmtest='php5-fpm -t'
alias php5fpmreload='php5-fpmtest && service php5-fpm reload'
alias php5fpmstatus='curl 127.0.0.1/status'
fi
fi
if [[ -f "${HOME}/.aliases.local" ]]; then
source "${HOME}/.aliases.local"
fi