-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
525 lines (481 loc) · 12.1 KB
/
.bashrc
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# ~/.bashrc
if [ -z "$PS1" ]; then
shopt -s expand_aliases
fi
export PS1='\h `gitbranch`\$ '
export PAGER=less
export PATH=/opt/local/libexec/gnubin:/opt/local/bin:/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/opt/local/sbin:~/data/prog/go/bin:~/.krew/bin
export GIT_PAGER='less -+S'
export HISTSIZE=2000
export HISTCONTROL=ignoredups
export LANG=en_US.UTF-8
export LESS='-XFR'
export MANLESS=:
export SYSTEMD_LESS=FRXMK
# ansible colors
export ANSIBLE_COLOR_OK='normal'
export ANSIBLE_COLOR_VERBOSE='normal'
# sane term
#export TERM=vt100
export TERM=xterm
# correct umask
umask 022
# vi-style editing
set -o vi
# enable ^L to clear screen
bind -m vi-insert "\C-l":clear-screen
# aliases
alias ?='echo'
alias a='ansible'
alias ai='ansible-inventory'
alias ap='ansible-playbook'
#alias b='bat -fp --theme=DarkNeon'
alias b='bat -fp --theme=Coldark-Cold'
alias b64='base64'
alias c='cat'
alias calicoctl='calicoctl --allow-version-mismatch'
alias cd..='cd ..'
alias cd...='cd ../..'
alias cd....='cd ../../..'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias cl='clear'
alias d='docker'
alias dco='docker-compose --ansi=never'
alias diff='diff --color=always -u'
alias dotupdate='curl https://raw.githubusercontent.com/akosela/dotfiles/master/.bashrc > ~/.bashrc'
alias dps="docker ps --format 'table {{.Image}}\t{{.Names}}\t{{.Ports}}\t{{.Command}}\t{{.Status}}'"
alias e='ex'
alias f='find'
alias g='grep'
alias gc='grep --color'
alias gdb='gdb -q -ex "set sty addr foreground none" -ex "set disassembly int"'
alias gob='go build -ldflags="-s -w"'
alias gor='go run'
alias h='head'
alias h1='head -1'
alias h2='head -2'
alias h5='head -5'
alias hi='history 20'
alias htop='htop -C'
alias i='ip -br a'
alias il='ip -br l'
alias ir='ip r'
alias j='journalctl'
alias k='kill'
alias l='less'
alias ll='ls -Fl'
alias llh='ls -Flh'
alias ls='ls -F'
alias lsd="ls -d */ | sed 's/\/$//g' | column -c80"
alias m='man'
alias md='mkdir'
alias n='netstat -pant'
alias p='echo'
alias print='echo'
alias o='pwd'
alias r='ip r'
alias s='ssh'
alias sb='sudo bash'
alias sudo='sudo '
alias t='tail'
alias t1='tail -1'
alias t2='tail -2'
alias t5='tail -5'
alias to='top -bn1 | head -25'
alias u='uptime'
alias un='uname'
alias v='vi'
alias vim='vi -u ~/.exrc.white'
alias x='exit'
alias y='yes'
alias z='kill'
alias zc='zcat'
alias zg='zgrep'
# systemctl aliases
alias daemon-reload='systemctl daemon-reload'
alias disable='systemctl disable'
alias enable='systemctl enable'
alias mask='systemctl mask'
alias reload='systemctl reload'
alias restart='systemctl restart'
alias start='systemctl start'
alias status='systemctl status'
alias stop='systemctl stop'
alias sts='systemctl status'
alias unmask='systemctl unmask'
# git aliases
alias add='git add'
alias bisect='git bisect'
alias blame='git blame'
alias br='git branch -vv'
alias branch='git branch -vv'
alias clean='git clean'
alias clone='git clone'
alias co='git checkout'
alias com='git commit -am'
alias commit='git commit -am'
alias conf='git config -l'
alias dif='git diff'
alias fetch='git fetch'
alias filter-branch='git filter-branch'
alias format-patch='git format-patch'
alias gg='git grep'
alias ggrep='git grep'
#alias glog="git log --graph --pretty=format:'%C(white bold)%h%Creset -%C(red bold)%d%Creset %s %C(cyan bold)(%cr)%Creset <%an>' --abbrev-commit"
alias glog="git log --graph --pretty=format:'%C(blue)%h%Creset -%C(red)%d%Creset %s %C(blue)(%cr)%Creset <%an>' --abbrev-commit"
alias init='git init'
alias lfs='git lfs'
#alias log="git log -n 10 --graph --pretty=format:'%C(white bold)%h%Creset -%C(red bold)%d%Creset %s %C(cyan bold)(%cr)%Creset <%an>' --abbrev-commit"
alias log="git log -n 10 --graph --pretty=format:'%C(blue)%h%Creset -%C(red)%d%Creset %s %C(blue)(%cr)%Creset <%an>' --abbrev-commit"
alias merge='git merge'
alias move='git mv'
alias pick='git cherry-pick'
alias psh='git push'
alias pull='git pull'
alias push='git push'
alias rebase='git rebase'
alias reflog='git reflog'
alias remote='git remote -v'
alias remove='git rm'
alias rst='git reset'
alias revert='git revert'
alias show='git show'
alias st='git status'
alias stash='git stash'
alias submod='git submodule'
alias switch='git switch'
alias tag='git tag'
# k8s aliases
alias annotate='kubectl annotate'
alias ann='kubectl annotate'
alias api-resources='kubectl api-resources'
alias api-versions='kubectl api-versions'
alias apply='kubectl apply'
alias app='kubectl apply'
alias attach='kubectl attach'
alias att='kubectl attach'
alias auth='kubectl auth'
alias autoscale='kubectl autoscale'
alias cert='kubectl certificate'
alias cluster-info='kubectl cluster-info'
alias completion='kubectl completion'
alias config='kubectl config'
alias cordon='kubectl cordon'
alias create='kubectl create'
alias cre='kubectl create'
alias ctl='kubectx'
alias ct-='kubectl -'
alias debug='kubectl debug'
alias deb='kubectl debug'
alias del='kubectl delete'
alias delete='kubectl delete'
alias des='kubectl describe'
alias describe='kubectl describe'
alias dp='kubectl describe pod'
alias dq='kubectl describe quota'
alias drain='kubectl drain'
alias edit='kubectl edit'
alias event='kubectl events'
alias exe='kubectl exec'
alias explain='kubectl explain'
alias exp='kubectl explain'
alias expose='kubectl expose'
alias gcm='get cm'
alias gcnp='get cnp'
alias gd='get deployment'
alias gds='get ds'
alias ge='eve'
alias getall='kubectl get all,cm,secret,ing'
alias getj='kubectl get -ojson'
alias getl='kubectl get --show-labels'
alias getpending='kubectl get pods -o custom-columns=NS:metadata.namespace,NAME:metadata.name,STATUS:status.phase,AGE:.metadata.creationTimestamp --field-selector=status.phase=Pending'
alias gettaint='kubectl get node -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints'
alias gety='kubectl get -oyaml'
alias gi='get ing'
alias gj='kubectl get -ojson'
alias gn='get node'
alias gp='get pod'
alias gperr='kubectl get pods -A |grep -E "NAMESPACE|CrashLoopBackOff|Error|ImagePullBackOff|ErrImagePull|Evicted|Failed|ContainerCreating|ContainerStatusUnknown|Pending|Terminating"'
alias gpv='get pv'
alias gpvc='get pvc'
alias grs='get rs'
alias gq='get quota'
alias gs='get svc'
alias gse='get secret'
alias gss='get sealedsecret'
alias gsts='get sts'
alias gv='get vs'
alias gy='kubectl get -oyaml'
alias img='image'
alias kcp='kubectl cp'
alias kdiff='kubectl diff'
alias kdif='kubectl diff'
alias kpatch='kubectl patch'
alias kset='kubectl set'
alias ktail='kubectl tail'
alias ktop='kubectl top'
alias ktree='kubectl tree'
alias kustomize='kubectl kustomize'
alias kus='kubectl kustomize'
alias kwait='kubectl wait'
alias label='kubectl label'
alias lab='kubectl label'
alias lim='res'
alias logs='kubectl logs'
alias nsl='kubens'
alias ns-='kubens -'
alias options='kubectl options'
alias opt='kubectl options'
alias pat='kubectl patch'
alias plugin='kubectl plugin'
alias port-forward='kubectl port-forward'
alias pf='kubectl port-forward'
alias proxy='kubectl proxy'
alias replace='kubectl replace'
alias rep='kubectl replace'
alias rollout='kubectl rollout'
alias rol='kubectl rollout'
alias run='kubectl run'
alias scale='kubectl scale'
alias taint='kubectl taint'
alias uncordon='kubectl uncordon'
# terraform aliases
alias console='terraform console'
alias destroy='terraform destroy'
alias force-unlock='terraform force-unlock'
alias format='terraform fmt'
alias graph='terraform graph'
alias import='terraform import'
alias login='terraform login'
alias logout='terraform logout'
alias output='terraform output'
alias plan='terraform plan'
alias providers='terraform providers'
alias refresh='terraform refresh'
alias state='terraform state'
alias tapply='terrraform apply'
alias tget='terraform get'
alias tf='terraform'
alias tinit='terraform init'
alias tshow='terraform show'
alias ttaint='terraform taint'
alias tuntaint='terraform untaint'
alias validate='terraform validate'
alias workspace='terraform workspace'
alias ws='terraform workspace'
gitbranch()
{
git branch --show-current 2> /dev/null | sed 's/\(.*\)/(\1) /'
}
up()
{
git log --all --decorate --oneline | grep -B 1 $(git rev-parse --short HEAD) |
awk '{print $1}' | head -1 | xargs -I {} git checkout {}
}
down()
{
git log --all --decorate --oneline | grep -A 1 $(git rev-parse --short HEAD) |
awk '{print $1}' | tail -1 | xargs -I {} git checkout {}
}
png()
{
ping -nc2 -s16 -W3 $1 |grep -e icmp -e from
}
get()
{
case "$@" in
*node*)
kubectl get "$@" |awk '{print $1, $2, $3}' |column -t
;;
*pod*)
kubectl get "$@" |awk '{print $1, $2, $3, $4}' |column -t
;;
*vs*|*volumesnapshot*)
kubectl get "$@" |awk '{print $1, $2}' |column -t
;;
*secret*)
kubectl get "$@" |awk '{print $1, $2}' |column -t
;;
*svc*|*service*)
kubectl get "$@" |awk '{print $1, $3, $4, $5}' |column -t
;;
*sealedsecret*)
kubectl get "$@"
;;
*deploy*|*deployment*)
kubectl get "$@" |awk '{print $1, $2, $3, $4}' |column -t
;;
*pvc*)
kubectl get "$@" |awk '{print $1, $2, $4, $5}' |column -t
;;
*)
kubectl get "$@"
;;
esac
}
getn()
{
kubectl get pod --all-namespaces --field-selector spec.nodeName=$1
}
getnode ()
{
kubectl describe pod $1 | grep Node:
}
getp()
{
kubectl get pod --all-namespaces \
-ojsonpath='{range .items[?(@.spec.nodeName)]}{.spec.nodeName}{"\n"}{end}' |
sort |uniq -c |sort -rn
}
getc()
{
kubectl get pod $1 -o jsonpath='{.spec.containers[*].name}'
echo
}
util()
{
kubectl describe node $1 |
sed -ne '/Name:/,+p' -e '/Capacity:/,+13p' -e '/Resource/,+6p'
}
laststate()
{
kubectl describe pod $1 | grep -B2 -A4 -e 'Image:' -e 'Last State:' |
grep -vE 'Container ID|Port|Image|Image ID|Args:|Command:|--'
}
res()
{
kubectl top pod $1
kubectl describe pod $1 |
grep -B1 -A3 -e 'Container ID' -e Requests: -e Limits: |
grep -vE 'Container ID|Port|Image|Image ID|Command|Restart Count|Liveness|Environment|--|Args:|State:|SeccompProfile'
}
image()
{
kubectl describe pod $1 |grep -e Image: |sort -nu
}
labels()
{
kubectl get $1 $2 -ojsonpath='{"annotations:\n"}{.metadata.annotations}{"\nlabels:\n"}{.metadata.labels}{"\n"}' |
sed 's/:/: /g ; s/.*,/ &/' | tr -d '{}"' |
cut -d, --output-delimiter=$'\n ' -f1-
}
vols()
{
kubectl get pod $1 -ojsonpath='{range .spec.volumes[*]}{.name}{"\n"}{" pvc: "}{.persistentVolumeClaim.claimName}{"\n"}{end}'
}
# eve <pod> -n <ns>
eve()
{
if [ ! -z $1 ]; then
if [ ! -z $3 ]; then
kubectl events --for pod/$1 -n $3
elif [ ! -z $2 ]; then
kubectl events -n $2
else
kubectl events --for pod/$1
fi
else
kubectl events
fi
}
getip()
{
kubectl get pods -o jsonpath='{range .items[*]}{.status.podIP}{"\t"}{.metadata.name}{"\n"}{end}'
}
mcd()
{
mkdir -p $1 && cd $1
}
dl()
{
diff -- $1 $2 |less
}
exesh()
{
kubectl exec -it $1 -- /bin/bash
}
tls()
{
oldifs=$IFS
IFS=":"
args=($*)
openssl s_client -connect ${args[0]}:${args[1]:-443} < /dev/null 2>&1 |
openssl x509 -noout -text
IFS=$oldifs
}
tlsend()
{
oldifs=$IFS
IFS=":"
args=($*)
openssl s_client -connect ${args[0]}:${args[1]:-443} < /dev/null 2>&1 |
openssl x509 -noout -enddate
IFS=$oldifs
}
tlspem()
{
oldifs=$IFS
IFS=":"
args=($*)
openssl s_client -connect ${args[0]}:${args[1]:-443} < /dev/null 2>&1 |
openssl x509 -outform pem
IFS=$oldifs
}
tlspemv()
{
oldifs=$IFS
IFS=":"
args=($*)
openssl s_client -connect ${args[0]}:${args[1]:-443} -showcerts < /dev/null \ 2>&1 | sed -n /CERTIFICATE/,/CERTIFICATE/p
IFS=$oldifs
}
tlsv()
{
oldifs=$IFS
IFS=":"
args=($*)
openssl s_client -connect ${args[0]}:${args[1]:-443} -showcerts < /dev/null \
2>&1
IFS=$oldifs
}
tlsprint()
{
openssl x509 -in $1 -noout -text
}
tlsprintend()
{
openssl x509 -in $1 -noout -enddate
}
tlscheck()
{
openssl x509 -noout -modulus -in $1 | openssl md5
openssl rsa -noout -modulus -in $2 | openssl md5
}
ct()
{
if [ ! -z $1 ]; then
kubectx $1
else
kubectx -c
fi
}
ns()
{
if [ ! -z $1 ]; then
kubens $1
else
kubens -c
fi
}
ceph()
{
tools=`kubectl get pod -n rook-ceph |grep tools |awk '{print $1}'`
kubectl exec -it $tools -n rook-ceph -- ceph $1 $2 $3
}
radosgw-admin()
{
tools=`kubectl get pod -n rook-ceph |grep tools |awk '{print $1}'`
kubectl exec -it $tools -n rook-ceph -- radosgw-admin $1 $2 $3
}