forked from flat235/dotfiles-flat235
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zshrc
1703 lines (1480 loc) · 52.8 KB
/
.zshrc
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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# vim: sw=4 et filetype=zsh
[ -z "$ZPROF" ] || zmodload zsh/zprof
# Reset Colors
export Color_Reset='\033[0m'
# Regular Colors
export Black='\033[0;30m'
export Red='\033[0;31m'
export Green='\033[0;32m'
export Yellow='\033[0;33m'
export Blue='\033[0;34m'
export Purple='\033[0;35m'
export Cyan='\033[0;36m'
export White='\033[0;37m'
# Bold
export Bold_Black='\033[1;30m'
export Bold_Red='\033[1;31m'
export Bold_Green='\033[1;32m'
export Bold_Yellow='\033[1;33m'
export Bold_Blue='\033[1;34m'
export Bold_Purple='\033[1;35m'
export Bold_Cyan='\033[1;36m'
export Bold_White='\033[1;37m'
# Underline
export Underline_Black='\033[4;30m'
export Underline_Red='\033[4;31m'
export Underline_Green='\033[4;32m'
export Underline_Yellow='\033[4;33m'
export Underline_Blue='\033[4;34m'
export Underline_Purple='\033[4;35m'
export Underline_Cyan='\033[4;36m'
export Underline_White='\033[4;37m'
# Background
export On_Black='\033[40m'
export On_Red='\033[41m'
export On_Green='\033[42m'
export On_Yellow='\033[43m'
export On_Blue='\033[44m'
export On_Purple='\033[45m'
export On_Cyan='\033[46m'
export On_White='\033[47m'
# High Intensity
export Intense_Black='\033[0;90m'
export Intense_Red='\033[0;91m'
export Intense_Green='\033[0;92m'
export Intense_Yellow='\033[0;93m'
export Intense_Blue='\033[0;94m'
export Intense_Purple='\033[0;95m'
export Intense_Cyan='\033[0;96m'
export Intense_White='\033[0;97m'
# Bold High Intensity
export Bold_Intense_Black='\033[1;90m'
export Bold_Intense_Red='\033[1;91m'
export Bold_Intense_Green='\033[1;92m'
export Bold_Intense_Yellow='\033[1;93m'
export Bold_Intense_Blue='\033[1;94m'
export Bold_Intense_Purple='\033[1;95m'
export Bold_Intense_Cyan='\033[1;96m'
export Bold_Intense_White='\033[1;97m'
# High Intensity backgrounds
export On_Intense_Black='\033[0;100m'
export On_Intense_Red='\033[0;101m'
export On_Intense_Green='\033[0;102m'
export On_Intense_Yellow='\033[0;103m'
export On_Intense_Blue='\033[0;104m'
export On_Intense_Purple='\033[0;105m'
export On_Intense_Cyan='\033[0;106m'
export On_Intense_White='\033[0;107m'
export ENABLE_ZSH_ASYNC_UPDATE_CHECK=true
export ENABLE_ZSH_AUTOSUGGEST=true
export ENABLE_ZSH_ENV_FILE_SOURCE=true
export ENABLE_ZSH_RANDOM_ALIAS_ON_START=false
export ENABLE_ZSH_SPACESHIP_PROMPT=false
export ENABLE_ZSH_SYNTAX_HIGHLIGHTING=true
export ZSH_PROMPT_EXIT_CODE_COLOR_FAILURE='red'
export ZSH_PROMPT_EXIT_CODE_PREFIX='with code'
export ZSH_PROMPT_EXIT_CODE_SUFFIX=''
export ZSH_PROMPT_SEPARATE_LINE=true
source ~/.zshrc.env
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) operatingSystem=Linux;;
Darwin*) operatingSystem=Mac;;
CYGWIN*) operatingSystem=Cygwin;;
MINGW*) operatingSystem=MinGw;;
*) operatingSystem="UNKNOWN:${unameOut}"
esac
unset unameOut
if [[ $operatingSystem == "Linux" ]]; then
n=$(nice)
# increse process priotiy if user is root, this is useful if you're loggin in while the system is under high load
if [[ $EUID -eq 0 ]]; then
renice -n -20 $$ >/dev/null 2>&1
ionice -c 2 -n 0 -p $$ >/dev/null 2>&1
fi
fi
if [[ $operatingSystem == "Mac" ]]; then
alias ls='ls -h -G'
alias make="make -j\$(sysctl -n hw.ncpu)"
else
alias ls='ls -h --color --group-directories-first'
alias make="make -j\$(nproc)"
fi
# ixon: enable XON/XOFF flow control
# ixoff: enable sending of start/stop characters
# iutf8: assume input characters are UTF-8 encoded
stty -ixon -ixoff 2>/dev/null
# put keyboard and console in unicode mode.
# UNICODE_START(1)
unicode_start 2>/dev/null
# set unicode mode
kbd_mode -u 2>/dev/null
if [[ "$TERM" == "dumb" ]]
then
unsetopt zle
unsetopt prompt_cr
unsetopt prompt_subst
unfunction precmd
unfunction preexec
PS1='$ '
return
fi
distro=''
if [[ $operatingSystem == "Linux" ]]; then
is_done=false
distro_result=$(lsb_release -i)
if [ $? -eq 0 ]; then
if [[ $distro_result =~ "Ubuntu" ]]; then
distro="Ubuntu"
fi
if [[ $distro_result =~ "Fedora" ]]; then
distro="Fedora"
fi
if [[ $distro_result =~ "Debian" ]]; then
distro="Debian"
fi
if [[ $distro_result =~ "Gentoo" ]]; then
distro="Gentoo"
fi
if [[ $distro_result =~ "Arch" ]]; then
distro="Arch"
fi
is_done=true
fi
unset is_done
unset distro_result
fi
alias get-distro="lsb_release -a"
alias get-distro-name="echo $distro"
function ask_yn {
if [ -n "$1" ]; then
cat << EOF
Function to interactivly ask a simple "YES / NO" question with.
Usage:
- Define "Yes" branch function like:
function ask_yn_y_callback { echo "You choose Yes"; }
- Define "No" branch function like:
function ask_yn_n_callback { echo "You choose No"; }
- Echo / Print your question (with a linebreak at the end)
- call ask_yn
- ask_yn_y_callback and ask_yn_n_callback do get unset automatically
Example:
function ask_yn_y_callback {
echo "You said yes, so doing stuff"
}
function ask_yn_n_callback {
echo "You said no, doing stuff"
}
echo "Do want to do it?"; ask_yn
EOF
return 1
fi
select yn in "Yes" "No"; do
case $yn in
Yes)
ask_yn_y_callback
break;;
No)
ask_yn_n_callback
break;;
esac
done
if [ -x ask_yn_y_callback ]; then
unset -f ask_yn_y_callback
fi
if [ -x ask_yn_n_callback ]; then
unset -f ask_yn_n_callback
fi
}
alias sudo='sudo SSH_AUTH_SOCK=$SSH_AUTH_SOCK'
alias sudosu='sudo su --whitelist-environment=SSH_AUTH_SOCK -l'
alias pls='sudo'
alias root='sudosu root'
alias tmux='tmux -2 -u'
alias tmuxa='tmux list-sessions 2>/dev/null 1>&2 && tmux a || tmux'
alias tmux-detach='tmux detach'
alias ll='ls -l'
alias la='ls -al'
alias l='la'
alias grep='grep --color'
alias less='less --RAW-CONTROL-CHARS' # only ANSI "color" escape sequences and OSC 8 hyperlink sequences are output in "raw" form.
if which bat &>/dev/null; then
alias bat='bat --decorations never'
alias cat='bat --paging=never'
fi
alias htop='htop -d 10'
alias iotop='iotop -d 1 -P -o'
alias rsync="rsync --progress --numeric-ids --human-readable --copy-links --hard-links"
alias brexit='echo "disable all network interfaces, delete 50% of all files and then reboot the dam thing!"; ask_yn_y_callback() { echo "See ya and peace out!"; exit; }; ask_yn_n_callback() { echo -n ""; }; ask_yn'
alias urlencode='python3 -c "import sys, urllib.parse; print(urllib.parse.quote_plus(sys.stdin.read()));"'
alias urldecode='python3 -c "import sys, urllib.parse; print(urllib.parse.unquote_plus(sys.stdin.read()));"'
alias ceph-osd-heap-release='ceph tell "osd.*" heap release' # release unused memory by the ceph osd daemon(s).
alias ceph-watch-status='watch -n 1 ceph -s'
alias reset-swap='sudo swapoff -a; sudo swapon -a'
alias reset-fscache='sync; sudo echo 3 > /proc/sys/vm/drop_caches'
alias get-ip-local='hostname -I'
alias get-ip-internet='curl https://ip.compilenix.org 2>/dev/null | xargs'
alias get-network-listening-netstat='sudo netstat -tunpl'
alias get-network-listening='sudo ss --numeric --listening --processes --tcp --udp'
alias get-network-active-connections-netstat='sudo netstat -tun'
alias get-network-active-connections='ss --numeric --processes --tcp --udp -o state synchronized'
alias get-network-active-connections-by-type-netstat="sudo netstat -tun | awk '{print \$6}' | sort | uniq -c | sort -n | tail -n +2"
alias get-network-active-connections-by-type="sudo ss --summary"
alias get-ip4tables='sudo iptables -L -v'
alias get-ip4tables-nat='sudo iptables -t nat -L -v'
alias get-ip6tables='sudo ip6tables -L -v'
alias get-ip6tables-nat='sudo ip6tables -t nat -L -v'
alias get-mem-dirty='cat /proc/meminfo | grep Dirty'
alias watch-mem-dirty='watch -n 1 "cat /proc/meminfo | grep Dirty"'
alias get-date='date +"%Y-%m-%d.%H%M"'
alias get-date-unixtime='date +%s'
alias get-date-from-unixtime='read a; date -d @$a'
alias get-date-hex='get-date | xargs printf "%x\n"'
alias get-date-from-hex-unixtime='read a; echo $a | echo $((16#$_))'
alias get-date-from-hex='get-date-from-hex-unixtime | date -d @$_'
alias get-date-rfc-5322='date --rfc-email'
alias get-date-rfc-email='get-date-rfc-5322'
alias get-date-rfc-2616='LC_TIME="en_US.UTF-8" TZ="GMT" date "+%a, %d %b %Y %T %Z"'
alias get-date-rfc-http='get-date-rfc-2616'
alias get-date-rfc-3339-day='date --rfc-3339=date'
alias get-date-rfc-3339-second='date --rfc-3339=second'
alias get-date-rfc-3339-ns='date --rfc-3339=ns'
alias get-date-iso-8601-day='date --iso-8601=date'
alias get-date-iso-8601-hour='date --iso-8601=hours'
alias get-date-iso-8601-second='date --iso-8601=seconds'
alias get-date-iso-8601-ns='date --iso-8601=ns'
alias get-calendar='cal --monday --week'
alias get-calendar-year='get-calendar --year'
alias get-hpkp-pin='openssl x509 -pubkey -noout | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -binary | openssl enc -base64'
function set-dns-query-stats-enable {
if [ -n "$1" ]; then
cat << EOF
Add "+stats" for "get-dns" function invocations.
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
export dns_query_stats='+stats'
}
function set-dns-query-stats-disable {
if [ -n "$1" ]; then
cat << EOF
Remove "+stats" for "get-dns" function invcations.
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
export dns_query_stats=''
}
function set-dns-query-additional-enable {
if [ -n "$1" ]; then
cat << EOF
Add "+additional" for "get-dns" function invocations.
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
export dns_query_additional='+additional'
}
function set-dns-query-additional-disable {
if [ -n "$1" ]; then
cat << EOF
Remove "+additional" for "get-dns" function invocations.
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
export dns_query_additional=''
}
set-dns-query-stats-enable
set-dns-query-additional-enable
alias get-dns="dig +noall \$(echo \$dns_query_stats) \$(echo \$dns_query_additional) +answer"
alias get-dns-dnssec="dig +noall \$(echo \$dns_query_stats) \$(echo \$dns_query_additional) +answer +dnssec"
alias get-dns-dnssec-verify="dig +noall \$(echo \$dns_query_stats) \$(echo \$dns_query_additional) +answer +dnssec +sigchase"
alias invoke-dns-retransfer='rndc retransfer'
alias invoke-dns-reload='rndc reload'
function compare-dns-soa-rr {
if [ -n "$1" ]; then
cat << EOF
Function to fetch and compare DNS SOA RR from differend dns servers.
Requirements:
- dig
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
local domain_name
echo -n "Domain name: "; read domain_name
local dns_servers
echo -n "DNS Server ip addresses (space separated): "; read dns_servers
local dns_server
for dns_server in ${=dns_servers}; do
echo "Testing $dns_server"
dig +noall +answer SOA "$domain_name" "@$dns_server"
dig +noall +answer NS "$domain_name" "@$dns_server"
done
}
alias get-picture-metadata-curl='echo -n "URL: "; read a; curl -sr 0-1024 $a | strings'
alias get-picture-metadata-file='echo -n "file path: "; read a; dd bs=1 count=1024 if=$a 2>/dev/null | strings'
alias get-random-alias='alias | sort --random-sort | head -n 1'
alias get-random-password-strong='echo -n "length: "; read len; cat /dev/random | tr -dc "[:print:]" | head -c $len | awk "{ print $1 }"' # awk adds a newline
alias get-random-password-alnum='echo -n "length: "; read len; cat /dev/random | tr -dc "[:alnum:]" | head -c $len | awk "{ print $1 }"'
alias get-random-password-alnum-lower='echo -n "length: "; read len; cat /dev/random | tr -dc "[:digit:][:lower:]" | head -c $len | awk "{ print $1 }"'
alias get-random-number-range='echo -n "from: "; read from; echo -n "to: "; read to; shuf -i ${from}-${to} -n 1'
alias get-random-guid='uuidgen'
alias get-random-hex='echo -n "length: "; read len; cat /dev/random | tr -dc "0-9a-f" | head -c $len | awk "{ print $1 }"'
alias get-random-ip4='python3 -c "import ipaddress, random; print(ipaddress.ip_address(random.randint(0, 0x7FFFFFFF)))"'
alias get-random-ip6='python3 -c "import ipaddress, random; print(ipaddress.ip_address(random.randint(0, 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)))"'
alias get-random-ip6-ula-network='python3 -c "from ipaddress import IPv6Network; import random; ula = IPv6Network(\"fd00::/8\"); print(IPv6Network((ula.network_address + (random.getrandbits(40) << 80), 48)))"'
alias get-random-port='shuf -i 16385-49151 -n 1'
alias get-fortune='echo -e "\n$(tput bold)$(tput setaf $(shuf -i 1-5 -n 1))$(fortune)\n$(tput sgr0)"'
alias get-process-zombie="ps --cols=9999 aux | awk '{if (\$8==\"Z\") { print \$1,\$2,\$11 }}'"
alias set-clipboard-x11="xclip -i -sel c -f"
alias set-clipboard-wayland="wl-copy"
alias get-clipboard-wayland="wl-paste"
alias get-ssh-pubkey='if [ -f ~/.ssh/id_ed25519.pub ]; then cat ~/.ssh/id_ed25519.pub; elif [ -f ~/.ssh/id_ed25519_pub ]; then content=$(cat ~/.ssh/id_ed25519_pub); fi; echo $content'
alias get-ssh-privkey='if [ -f ~/.ssh/id_ed25519 ]; then cat ~/.ssh/id_ed25519; elif [ -f ~/.ssh/id_ed25519 ]; then content=$(cat ~/.ssh/id_ed25519_pub); fi; echo $content'
alias get-ssh-pubkeys-host='(for file in /etc/ssh/*_key.pub; do echo "$file"; ssh-keygen -l -E md5 -f $file; ssh-keygen -l -E sha256 -f "$file"; echo; done)'
function get-debian-package-description {
if [[ "$1" =~ ^(--help|-h)$ ]] || [ ! -n "$1" ]; then
cat << EOF
Get the description of a debian package.
Requirements:
- awk
- dpkg
- grep
- sed
Usage: $(echo $funcstack[-1]) package_name
Example: $(echo $funcstack[-1]) apt
EOF
return 1
fi
dpkg -l "$1" | grep --color " $1 " | awk '{$1=$2=$3=$4="";print $0}' | sed 's/^ *//'
}
function get-debian-package-description-pipe {
if [ -n "$1" ]; then
cat << EOF
Get the description of a debian package, via piping.
Requirements:
- awk
- dpkg
- grep
- sed
Usage: $(echo $funcstack[-1])
Example: echo apt | $(echo $funcstack[-1])
EOF
return 1
fi
local input
read input
get-debian-package-description "$input"
}
function get-debian-package-updates {
if [ -n "$1" ]; then
cat << EOF
List all avaliable debian package updates.
Requirements:
- apt
- perl
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
apt --just-print upgrade 2>&1 | perl -ne 'if (/Inst\s([\w,\-,\d,\.,~,:,\+]+)\s\[([\w,\-,\d,\.,~,:,\+]+)\]\s\(([\w,\-,\d,\.,~,:,\+]+)\)? /i) {print "$1 (\e[1;34m$2\e[0m -> \e[1;32m$3\e[0m)\n"}'
}
function get-dataurl {
if [[ "$1" =~ ^(--help|-h)$ ]] || [ ! -n "$1" ]; then
cat << EOF
Function to generate a data URL from a file.
Requirements:
- openssl
- tr
Usage: $(echo $funcstack[-1]) file
file path to a file
Example:
$(echo $funcstack[-1]) ./some.jpg
EOF
return 1
fi
local mimeType
mimeType=$(file -b --mime-type "$1")
if [[ $mimeType == text/* ]]; then
mimeType="${mimeType};charset=utf-8"
fi
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"
}
alias set-zsh-highlighting-full='ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern line)'
alias set-zsh-highlighting-default='ZSH_HIGHLIGHT_HIGHLIGHTERS=(main)'
alias set-zsh-highlighting-off='ZSH_HIGHLIGHT_HIGHLIGHTERS=()'
alias set-terminal-powersave-off='setterm -blank 0 -powersave off'
alias set-terminal-powersave-on='setterm -blank 60 -powersave on'
alias set-megaraid-alarm-enabled='sudo megacli -AdpSetProp AlarmEnbl'
alias set-megaraid-alarm-disabled='sudo megacli -AdpSetProp AlarmDsbl'
alias set-megaraid-alarm-silent='sudo megacli -AdpSetProp AlarmSilence'
alias set-keyboard-mode-raw='sudo kbd_mode -s'
alias set-display-off-x11='sleep 1; xset dpms force standby'
alias set-display-on-x11='xset dpms force on'
alias set-display-off-wayland="swayidle timeout 1 'swaymsg \"output * dpms off\"' resume 'swaymsg \"output * dpms on\"; pkill -nx swayidle'"
alias set-display-on-wayland='swaymsg "output * dpms on"'
alias update-gentoo='echo "do a \"emerge --sync\"?"; ask_yn_y_callback() { sudo emerge --sync; }; ask_yn_n_callback() { echo ""; }; ask_yn; sudo emerge -avDuN world'
alias update-archlinux-pacman='sudo pacman -Syu'
alias update-archlinux-yaourt='sudo yaourt -Syu'
alias update-archlinux-yaourt-aur='sudo yaourt -Syu --aur'
function update-debian {
if [ -n "$1" ]; then
cat << EOF
Install all Debian package updates:
- apt update
- apt autoremove
- apt upgrade
- apt autoremove
- apt autoclean
Requirements:
- apt
- sudo
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
echo "do an \"apt update\"?"
function ask_yn_y_callback {
set -x
sudo apt update
set +x
}
function ask_yn_n_callback {
echo ""
}
ask_yn
set -x
sudo apt autoremove
apt list --upgradable
sudo apt upgrade
sudo apt autoremove
sudo apt autoclean
set +x
}
alias update-yum='sudo yum update --refresh'
function update-fedora {
if [ -n "$1" ]; then
cat << EOF
Install all Debian package updates:
- dnf update
- dnf autoremove
Requirements:
- dnf
- sudo
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
set -x
sudo dnf update --refresh
sudo dnf autoremove
set +x
}
alias gitg='git gui'
function reset-git {
if [[ "$1" =~ ^(--help|-h)$ ]] || [ ! -n "$1" ]; then
cat << EOF
Invoke "git reset --hard" for all parameter directories.
Requirements:
- git
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
for i in $*; do
if [ ! -d "$i" ]; then
echo "$(echo $funcstack[-1]): Not a directory: $i"
continue
fi
if [ ! -d "$i/.git" ]; then
echo "$(echo $funcstack[-1]): Not a git directory: $i"
continue
fi
echo -e "$(echo $funcstack[-1]): \033[0;36mgit reset --hard $i\033[0;0m"
pushd "$i" >/dev/null
git reset --hard
popd >/dev/null
done
}
function update-dotfiles-non-interactive {
if [ -n "$1" ]; then
cat << EOF
Update dotfiles.
Requirements:
- cat
- chmod
- chown
- git
- ln
- mkdir
- mv
- python 3.8+
- tar
- touch
- unlink
- zstd
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
reset-git ~/dotfiles
pushd ~/dotfiles >/dev/null
git pull --all
./update.sh
popd >/dev/null 2>&1
if [ -f "/tmp/$USER-zsh-dotfiles-async-update-exists.yep" ]; then
rm "/tmp/$USER-zsh-dotfiles-async-update-exists.yep"
fi
}
function update-dotfiles {
if [ -n "$1" ]; then
cat << EOF
Update dotfiles.
Requirements:
- cat
- chmod
- chown
- git
- ln
- mkdir
- mv
- python 3.8+
- tar
- touch
- unlink
- zstd
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
pushd ~/dotfiles >/dev/null
git status
popd >/dev/null 2>&1
echo "This will reset all changes you may made to files which are symlinks at your home directory, to check this your own: \"# cd ~/dotfiles && git status\""
echo "Do you want proceed with the update?"
function ask_yn_y_callback {
update-dotfiles-non-interactive
}
function ask_yn_n_callback {
# remove avaliable update indcator
if [ -f "/tmp/$USER-zsh-dotfiles-async-update-exists.yep" ]; then
rm "/tmp/$USER-zsh-dotfiles-async-update-exists.yep" 2>/dev/null
fi
}
ask_yn
}
alias disable-dotfiles-update-prompt-temp='touch "/tmp/$USER-zsh-dotfiles-async-update-check.disabled"'
alias update-code-insiders-rpm='wget "https://go.microsoft.com/fwlink/?LinkID=760866" -O /tmp/code-insiders.rpm && sudo yum install -y /tmp/code-insiders.rpm && rm /tmp/code-insiders.rpm'
alias test-mail-sendmail='echo -n "To: "; read mail_to_addr; echo -e "From: ${USER}@$(hostname -f)\nTo: ${mail_to_addr}\nSubject: test subject\n\ntest body" | sendmail -v "${mail_to_addr}"'
alias test-mail-mutt='mutt -s "test" '
function send-mail {
if [[ "$1" =~ ^(--help|-h)$ ]] || [ ! -n "$1" ] || [ ! -n "$2" ]; then
cat << EOF
Function to send a test e-mail using sendmail.
Requirements:
- sendmail
Usage: $(echo $funcstack[-1]) recipient subject
recipient recipient e-mail address
subject the subject of the message
Example:
echo "Test message body" | $(echo $funcstack[-1]) person@domain.tld "Test Subject"
EOF
return 1
fi
local to="$1"
local subject="$2"
local body="$(< /dev/stdin)"
cat << EOF | sendmail "$to"
From: ${USER}@$(hostname -f)
To: $to
Subject: $subject
$body
EOF
}
function apache-configtest {
if [ -n "$1" ]; then
cat << EOF
Test apache configuration.
Requirements:
- apache2ctl
- sudo
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
sudo apache2ctl -t
}
function apache-reload {
if [ -n "$1" ]; then
cat << EOF
Test apache configuration and invoke configuration reload.
Requirements:
- apache2ctl
- sudo
- systemctl
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
apache-configtest && { sudo systemctl reload apache2 || sudo systemctl status apache2 }
}
function apache-restart {
if [ -n "$1" ]; then
cat << EOF
Test apache configuration and invoke a service restart.
Requirements:
- apache2ctl
- sudo
- systemctl
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
apache-configtest && { sudo systemctl restart apache2 || sudo systemctl status apache2 }
}
function nginx-status {
if [ -n "$1" ]; then
cat << EOF
Show current nginx service status.
Requirements:
- sudo
- systemctl
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
sudo systemctl status nginx
}
function nginx-configtest {
if [ -n "$1" ]; then
cat << EOF
Test nginx configuration.
Requirements:
- nginx
- sudo
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
sudo nginx -t
}
function nginx-reload {
if [ -n "$1" ]; then
cat << EOF
Test nginx configuration and invoke configuration reload.
Requirements:
- nginx
- sudo
- systemctl
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
nginx-configtest && { sudo systemctl reload nginx || sudo systemctl status nginx }
}
function nginx-restart {
if [ -n "$1" ]; then
cat << EOF
Test nginx configuration and invoke a service restart.
Requirements:
- nginx
- sudo
- systemctl
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
nginx-configtest && { sudo systemctl restart nginx || sudo systemctl status nginx }
}
function view-logfile {
if [[ "$1" =~ ^(--help|-h)$ ]] || [ ! -n "$1" ]; then
cat << EOF
Function to view a log file, with log syntax highlighting.
Requirements:
- cat
- ccze
- less
- sudo
Usage: $(echo $funcstack[-1]) file
file path to a file
Example:
$(echo $funcstack[-1]) /var/log/messages.log
EOF
return 1
fi
file="$1"
sudo cat "${file}" | ccze -A | less -R
}
alias get-processes='ps --cols=9999 aux'
alias get-processes-systemd='systemd-cgls'
alias get-memory='free -h -m'
alias get-disk-space='df -h'
alias get-disk-space-filtered='echo "Filesystem Size Used Avail Use% Mounted on"; df -h | sort | grep --color=no -E "^/dev/"'
alias get-disks='lsblk -f'
alias get-mounts='mount | column -t'
alias start-stopwatch='echo "press Ctrl+D to stop"; time cat'
alias install-node-fnm='curl https://raw.githubusercontent.com/Schniz/fnm/master/.ci/install.sh | bash'
alias install-rust="curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
alias add-user='useradd'
alias remove-user='deluser'
alias docker-inspect-image='dive' # https://github.com/wagoodman/dive
alias get-hostname='hostname -s'
alias get-hostname-fqdn='hostname -f'
alias get-hostname-domain='hostname -d'
alias view-kernel-log='dmesg -H'
alias view-history='history | sort --reverse | less'
alias remove-history='echo >$HOME/.history; history -p'
alias get-systemd-units='systemctl list-units'
alias get-systemd-units-service='systemctl list-units --type service'
alias get-systemd-units-failed='systemctl list-units --state failed'
alias get-systemd-units-timer='systemctl list-timers'
alias reload-systemd-units='systemctl daemon-reload'
alias get-kernel-psi='for i in /proc/pressure/*; do echo $(basename $i); cat $i; echo; done'
function get-time-chrony-status {
if [ -n "$1" ]; then
cat << EOF
Get the current state of connected ntp upstream sources.
Requirements:
- chronyc
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
local fn_name=$(echo $funcstack[-1])
echo "+$fn_name> systemctl status chronyd.service"
systemctl status chronyd.service
echo
echo "+$fn_name> chronyc -n activity # Check how many NTP sources are online/offline"
chronyc -n activity
echo
echo "+$fn_name> chronyc -n tracking # Display system time information"
chronyc -n tracking
echo
echo "+$fn_name> chronyc -n ntpdata # Display information about last valid measurement"
chronyc -n ntpdata
echo
echo "+$fn_name> chronyc -n selectdata # Display information about source selection"
chronyc -n selectdata
echo
echo "+$fn_name> chronyc -n sources # Display information about current sources"
chronyc -n sources
echo
echo "+$fn_name> chronyc -n sourcestats # Display statistics about collected measurements"
chronyc -n sourcestats
}
function get-aliases-dotfiles {
if [ -n "$1" ]; then
cat << EOF
Get list of all zsh aliases defined by dotfiles.
Requirements:
- grep
- sort
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
grep -E '^alias ' ~/.zshrc | sort
}
function get-functions-dotfiles {
if [ -n "$1" ]; then
cat << EOF
Get list of all zsh functions defined by dotfiles.
Requirements:
- awk
- grep
- sort
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
grep -E '^function ' ~/.zshrc | awk '{ print $2 }' | sort
}
function insert-datetime {
if [ -n "$1" ]; then
cat << EOF
Function to insert a timestamp at the beginning of each line passed into stdin.
Requirements:
- awk
Usage: $(echo $funcstack[-1])
file path to a file
Example:
echo fooo 2>&1 1>/dev/null | $(echo $funcstack[-1]) | tee /tmp/test.log
Result:
[2021-03-30 19:03:02 CEST]: fooo
EOF
return 1
fi
awk '{ print strftime("[%F %X %Z]:"), $0; fflush(); }'
}
alias virtualenv='python3 -m venv'
function format-text-lines-tabbed-into-table {
if [ -n "$1" ]; then
cat << EOF
Function to format multilined text into a table, separated by tabs.
Can be used in a pipe.
Requirements:
- cat
- column
- printf
- tr
Example:
\`\`\`test.txt
col1 col2 col3 col4 col5
value1 value2value2value2 value3 value4 value5
value1 value2 value3value3 value4 value5
value1 value2 value3 value4 value5
value1 value2 value3 value4 value5value5value5
\`\`\`
\`\`\`sh
cat test.txt | format-text-lines-tabbed-into-table
\`\`\`
Usage: $(echo $funcstack[-1])
EOF
return 1
fi
cat | tr -s '\t' | column -t -s"$(printf '\t')"
}
function format-text-lines-spaced-into-table {
if [ -n "$1" ]; then
cat << EOF
Function to format multilined text into a table, separated by spaces.
Can be used in a pipe.
Requirements:
- cat
- column
- printf
- tr
Example:
\`\`\`test.txt
col1 col2 col3 col4 col5
value1 value2value2value2 value3 value4 value5
value1 value2 value3value3 value4 value5
value1 value2 value3 value4 value5
value1 value2 value3 value4 value5value5value5
\`\`\`
\`\`\`sh
cat test.txt | format-text-lines-spaced-into-table
\`\`\`
Usage: $(echo $funcstack[-1])
EOF
return 1
fi