-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliases.zsh
470 lines (430 loc) · 17.3 KB
/
aliases.zsh
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
468
469
470
#=========================================================================
# ---------------| Directories |---------------
#=========================================================================
alias ~="cd $HOME"
alias dotfiles="$HOME/.dotfiles"
alias repos="cd $HOME/repos"
alias github="cd $HOME/repos/github"
alias gitlab="cd $HOME/repos/gitlab"
alias gitea="cd $HOME/repos/gitea"
if [[ "$(uname -s)" == "Linux" ]]; then
alias workspace='cd $HOME/workspace'
fi
if [[ "$(uname -s)" == "Darwin" ]]; then
alias doc="cd $HOME/documents"
alias dl="cd $HOME/downloads"
alias app="cd /applications"
alias workspace="cd $HOME/documents/workspace"
alias snippets="cd $HOME/documents/workspace/snippets"
fi
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| List & Size |---------------
#=========================================================================
if [ -x "$(command -v eza)" ]; then
alias ls='eza --long --group --icons --header --git --binary'
alias ls.='eza --long --group --icons --header --git --binary --all'
alias tree='eza --tree --icons'
alias tree.='eza --tree --icons --all'
else
alias ls='ls -lhF'
alias ls.='ls -lhFa'
alias tree='tree'
fi
alias tree-="tree"
alias size="du -sh"
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Prompt & Confirmation |---------------
#=========================================================================
alias rm='rm -iv'
alias mv='mv -iv'
alias cp='cp -iv'
alias ln='ln -iv'
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Open Application |---------------
#=========================================================================
alias subl="open -a /Applications/Sublime\ Text.app"
alias idea="open -a IntelliJ\ IDEA"
alias vsc='open -a /Applications/Visual\ Studio\ Code.app'
alias typora='open -a /Applications/Typora.app'
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| File Editing |---------------
#=========================================================================
alias edit-aliases='open -a /Applications/Sublime\ Text.app ~/.dotfiles/aliases.zsh'
alias edit-zshrc='open -a /Applications/Sublime\ Text.app ~/.dotfiles/.zshrc'
alias edit-path='open -a /Applications/Sublime\ Text.app ~/.dotfiles/path.zsh'
alias edit-hosts='open -a /Applications/Sublime\ Text.app /etc/hosts'
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Terminal |---------------
#=========================================================================
alias terminal-reload='source ~/.dotfiles/.zshrc'
alias vbrestart='sudo "/Library/Application Support/VirtualBox/LaunchDaemons/VirtualBoxStartup.sh" restart'
copyit() {
cat $1 | pbcopy && echo 'Copied to clipboard'
}
# See all paths, one element per line. If an argument is supplied, grep fot it.
pathls() {
test -n "$1" && {
echo $PATH | perl -p -e "s/:/\n/g;" | grep -i "$1"
} || {
echo $PATH | perl -p -e "s/:/\n/g;"
}
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| rsync |---------------
#=========================================================================
rcp() {
if [[ $# -eq 2 ]]; then
rsync -avzh --stats --progress $1 $2
else
echo "Usage: rcp <source> <destination>"
fi
}
rdl() {
if [[ $# -eq 1 ]]; then
rsync -avzh --stats --progress $1 ~/downloads
else
echo "Usage: rdl <source>"
fi
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Network Utility |---------------
#=========================================================================
alias fdns="sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder && echo 'DSN Flushed'"
alias myip="curl https://ipecho.net/plain"
alias whoisme="curl -s "http://ifconfig.co/json" | jq -r '.'"
alias ipv6="curl -s ipv6.icanhazip.com"
whoisip() {
curl -s http://ip-api.com/json/$1 | jq -r '.'
}
listening() {
if [ $# -eq 0 ]; then
sudo lsof -nP -iTCP -sTCP:LISTEN
elif [ $# -eq 1 ]; then
sudo lsof -nP -iTCP -sTCP:LISTEN | grep -i --color=auto $1
else
echo "Usage: listening [port/appname]"
fi
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Others |---------------
#=========================================================================
ssl-info() {
if [[ $# -eq 1 ]]; then
echo | openssl s_client -servername hostname -connect $1:443 2>/dev/null | openssl x509 -noout -text
fi
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Git |---------------
#=========================================================================
if [ -x "$(command -v git)" ]; then
alias clone='git clone'
alias add='git add .'
alias commit='git commit -m'
alias status='git status'
alias log='git log'
alias push='git push -u'
alias pull='git pull'
alias nah='git reset --hard && git clean -df'
alias nahto='git reset --hard'
alias nahtomain='git fetch --all && git reset --hard origin/main'
alias bls='git branch -a'
alias checkout='git checkout'
alias checkoutnew='git checkout -b'
alias brm='git branch -D'
alias setorigin='git remote set-url origin'
alias origin='git remote show origin'
alias rls='git remote -v'
alias remoterm='git remote remove'
alias remoteren='git remote rename'
alias commit-count='git rev-list --count'
alias grm='rm -rf .git*'
alias repo="gh repo"
alias merge="git merge"
# alias squash-all="count=$(git rev-list --count HEAD); git rebase -i HEAD~$((count - 1))"
fi
gls() {
if [[ $# -eq 1 ]]; then
curl -s https://api.github.com/users/$1/repos | jq '.[]|["name: "+.name,"url: "+.html_url,"clone: "+.clone_url,"ssh: "+.ssh_url]'
else
echo "Usage: gls <github username>"
fi
}
gio() {
if [[ $# -eq 2 ]]; then
curl https://git.io/ -i -F "url=$1" -F "code=$2"
else
echo "Usage: gio <url> <code>"
fi
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Terraform |---------------
#=========================================================================
if [ -x "$(command -v terraform)" ]; then
alias tinit='terraform init'
alias fmt='terraform fmt'
alias validate='terraform validate'
alias plan='terraform fmt && terraform validate && terraform plan'
alias apply='terraform apply'
alias output='terraform output'
alias state='terraform state'
alias show='terraform show'
alias tws='terraform workspace'
fi
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Kubernetes |---------------
#=========================================================================
if [ -x "$(command -v kubectl)" ]; then
alias kctl='kubectl'
alias k='kubectl'
alias pod-lens='kubectl pod-lens'
alias node-shell='kubectl node-shell'
alias open-svc='kubectl open-svc'
alias watch-all="watch kubectl get all,ing,pvc $@"
alias watch-pod="watch kubectl get pod -o wide --sort-by=.metadata.creationTimestamp $@"
alias watch-node="watch kubectl get node -o wide --sort-by=.metadata.creationTimestamp $@"
alias watch-pv="watch kubectl get pv,pvc $@"
alias watch-ing="watch kubectl get ing $@"
alias get-all="kubectl get all,pvc,ing,secret,cm $@"
alias get-events="kubectl get events --sort-by='.metadata.managedFields[0].time'"
alias get-pod="kubectl get pod $@"
alias get-pod-all="kubectl get pod -o wide --sort-by=.metadata.creationTimestamp --all-namespaces $@"
alias get-pv="kubectl get pv $@"
alias get-pvc="kubectl get pvc $@"
alias get-ing="kubectl get ing $@"
alias get-secret="kubectl get secret $@"
alias get-cm="kubectl get cm $@"
fi
alias kx='kubectx'
alias kns='kubens'
klogs() {
if [[ $# -eq 2 ]]; then
kubectl logs -f -n $1 $(kubectl get po -n $1 | egrep -o "$2[a-zA-Z0-9-]+")
else
echo "Usage: klogs <namespace> <pod prefix>"
echo "ezample: klogs <kube-system> <aws-load-balancer-controller>"
fi
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Vagrant |---------------
#=========================================================================
if [ -x "$(command -v vagrant)" ]; then
alias vssh="vagrant ssh"
alias vup="vagrant up"
alias vsuspend="vagrant suspend"
alias vresume="vagrant resume"
alias vreload="vagrant reload"
alias reloadp="vagrant reload --provision"
alias vhalt="vagrant halt"
alias globalstatus="vagrant global-status"
alias box-list='vagrant box list'
alias box-remove='vagrant box remove'
alias box-add='vagrant box add'
fi
destroy() {
if [ -e .vagrant ]; then
vagrant destroy
elif [ -e .terraform ]; then
terraform destroy
else
echo "This action isn't allowed to run in this directory"
fi
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Docker |---------------
#=========================================================================
if [ -x "$(command -v docker)" ]; then
alias dls='docker container list --all --format "table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"'
alias dps="docker ps --all --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}\t{{.Ports}}'"
alias dstart='docker start'
alias dsa='docker ps -aq | xargs docker stop'
alias dstop='docker stop'
alias drma='docker ps -aq | xargs docker rm -f'
alias drm='docker rm -f'
alias drmi='docker rmi -f'
alias drmia='docker images -aq | xargs docker rmi -f'
alias dit='docker exec -it'
alias dlogs='docker logs'
alias di='docker images'
alias dc='docker-compose'
alias dcupd='docker-compose up -d'
alias dcup='docker-compose up'
alias dcdown='docker-compose down'
alias dcbuild='docker-compose build'
alias dins='docker inspect'
alias dip="docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'"
fi
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Youtube download |---------------
#=========================================================================
ydl() {
if [ $# = 2 ]; then
path='$HOME/Downloads/%(title)s-%(id)s.%(ext)s'
# path='%(title)s.%(ext)s'
back="&& cd -"
case $1 in
mp3) youtube-dl --ignore-errors --output $path --extract-audio --audio-format mp3 $2 ;;
m4a) youtube-dl --ignore-errors --output $path --extract-audio --audio-format m4a $2 ;;
wav) youtube-dl --ignore-errors --output $path --extract-audio --audio-format wav $2 ;;
aac) youtube-dl --ignore-errors --output $path --extract-audio --audio-format aac $2 ;;
audio) youtube-dl --ignore-errors --output $path --extract-audio --audio-format best $2 ;;
video) youtube-dl -f bestvideo+bestaudio --output $path $2 ;;
playlist) youtube-dl -f bestvideo+bestaudio --yes-playlist --output $path $2 ;;
*) echo "Usage: ydl audio url" ;;
esac
else
local -r flagsTable=$(
printf "%s\n" \
"ydl video youtube-url Download audio and video with best quality" \
"ydl audio youtube-url Download only audio" \
"ydl playlist youtube-url Download playlist" \
"ydl mp3 youtube-url Download only audio in mp3 format" \
"ydl m4a youtube-url Download only audio in m4a format" \
"ydl wav youtube-url Download only audio in wav format" \
"ydl aac youtube-url Download only audio in aac format"
)
echo -e "$flagsTable"
fi
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Markdown |---------------
#=========================================================================
alias toc='gh-md-toc'
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Archive |---------------
#=========================================================================
# Extract archive
extract() {
if [ -f $1 ]; then
case $1 in
*.tar) tar xf $1 ;;
*.tar.bz2) tar xjvf $1 ;;
*.tar.gz) tar xzvf $1 ;;
*.tar.xz) tar xvf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.gz) gunzip $1 ;;
*.zip) unzip $1 ;;
*) echo "'$1' cannot be extracted with this method!!!" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Linux |---------------
#=========================================================================
# Manage Package
if [ -x "$(command -v apt)" ]; then
alias update='sudo apt update'
alias upgrade='sudo apt dist-upgrade'
alias install='sudo apt install'
alias autoremove='sudo apt autoremove'
fi
# Systemctl
if [ -x "$(command -v systemctl)" ]; then
alias ctlrestart='sudo systemctl restart' # Start or restart one or more units
alias ctlstatus='sudo systemctl status' # Show runtime status of one or more units
alias ctlstop='sudo systemctl stop' # Stop (deactivate) one or more units
alias ctlstart='sudo systemctl start' # Start (activate) one or more units
alias ctlreload='sudo systemctl reload' # Reload one or more units
alias ctlenable='sudo systemctl enable' # Enable one or more unit files
alias ctldisable='sudo systemctl disable' # Disable one or more unit files
alias ctlkill='sudo systemctl kill' # Send signal to processes of a unit
alias ctlclean='sudo systemctl clean' # Clean runtime, cache, state, logs or configuration of unit
alias ctlisactive='sudo systemctl is-active' # Check whether units are active
alias ctlisfailed='sudo systemctl is-failed' # Check whether units are failed
fi
# Basic functions
ips() {
if [[ $(ip -4 addr | grep inet | grep -vEc '127(\.[0-9]{1,3}){3}') -eq 1 ]]; then
echo
ip -4 addr | grep -w inet | grep -vE '127(\.[0-9]{1,3}){3}' | awk '{ print "\033[0;31m"$7"\033[0m"": ""\033[0;33m"$2"\033[0m"}'
else
echo
ip -4 addr | grep -w inet | grep -vE '127(\.[0-9]{1,3}){3}' | awk '{ print "\033[0;31m"$7"\033[0m"": ""\033[0;33m"$2"\033[0m"}' | nl -s '| '
fi
}
# Cloud-init
alias cloud-init-output='less +F /var/log/cloud-init-output.log'
alias cloud-init-status='sudo cloud-init status --wait --long'
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
#=========================================================================
# ---------------| Libvirt |---------------
#=========================================================================
if [ -x "$(command -v virsh)" ]; then
alias vls='sudo virsh list --all'
alias vlssnap='sudo virsh snapshot-list'
alias vlspool='sudo virsh pool-list'
alias vlsnet='sudo virsh net-list'
alias vlsvol='sudo virsh vol-list'
alias vinfo='sudo virsh dominfo'
alias vshutdown='sudo virsh shutdown'
alias vstart='sudo virsh start'
alias vautostart='sudo virsh autostart'
alias vreboot='sudo virsh reboot'
alias vreset='sudo virsh reset'
alias vcreate='sudo virsh create'
alias vdump='sudo virsh dumpxml'
alias vedit='sudo virsh edit'
fi
# Delte KVM instance
vDestroy() {
if [ -z $1 ]; then
echo "Instance name required!!"
fi
sudo virsh shutdown $1
sudo virsh destroy $1
sudo virsh undefine $1
sudo rm -rfv /var/lib/libvirt/pool/default/$1.qcow2
if [ -f /var/lib/libvirt/images/$1-seed.qcow2 ]; then
sudo rm -rfv /var/lib/libvirt/images/$1-seed.qcow2
fi
}
# Create KVM Screenshot
vCreateScreenshot() {
if [ -z $1 ]; then
echo "Instance name required!!"
fi
if [ -z $2 ]; then
echo "Screenshot name required!!"
fi
sudo virsh snapshot-create-as --domain $1 --name $2 --description $2
}
# Revert KVM Screenshot
vRevertScreenshot() {
if [ -z $1 ]; then
echo "Instance name required!!"
fi
if [ -z $2 ]; then
echo "Screenshot name required!!"
fi
sudo virsh snapshot-revert --domain $1 --snapshotname $2 --running
}
# Delte KVM Screenshot
vDeleteScreenshot() {
if [ -z $1 ]; then
echo "Instance name required!!"
fi
if [ -z $2 ]; then
echo "Screenshot name required!!"
fi
sudo virsh snapshot-delete --domain $1 --snapshotname $2
}
#[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]