-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.zshrc
1114 lines (899 loc) · 40.6 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
#!/bin/zsh
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ________ ________ ___ ___ _______ ___ ___ ║
# ║ |\_____ \|\ ____\|\ \|\ \|\ ___ \ |\ \ |\ \ ║
# ║ \|___/ /\ \ \___|\ \ \\\ \ \ __/|\ \ \ \ \ \ ║
# ║ / / /\ \_____ \ \ __ \ \ \_|/_\ \ \ \ \ \ ║
# ║ / /_/__\|____|\ \ \ \ \ \ \ \_|\ \ \ \____\ \ \____ ║
# ║ |\________\____\_\ \ \__\ \__\ \_______\ \_______\ \_______\ ║
# ║ \|_______|\_________\|__|\|__|\|_______|\|_______|\|_______| ║
# ║ \|_________| ║
# ║ ║
# ║ xn--gckvb8fzb.com * github.com/mrusme * [email protected] ║
# ║ ║
# ╚════════════════════════════════════════════════════════════════════════════╝
# zmodload zsh/zprof
unset LS_COLORS
unset LSCOLORS
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Basics ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export OS="$(uname | tr '[:upper:]' '[:lower:]')"
function __is_available {
prog="${1}"
os="${2}"
if [ "${os}" != "" ] && [ "${os}" != "${OS}" ]
then
return 1
fi
type "${prog}" > /dev/null
return "$?"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Exports ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export ZSH_TMUX_AUTOSTART=true
[ "${USER}" = "root" ] \
&& export ZSH_TMUX_AUTOSTART="false"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export XCURSOR_THEME="Vimix-White"
export XCURSOR_SIZE="32"
export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_CACHE_HOME="${HOME}/.cache"
export XDG_DATA_HOME="${HOME}/.local/share"
export XDG_DOWNLOAD_DIR="${HOME}/downloads"
export XDG_DESKTOP_DIR="${HOME}/desktop"
export XDG_TEMPLATES_DIR="${HOME}/"
export XDG_PUBLICSHARE_DIR="${HOME}/shared/public"
export XDG_DOCUMENTS_DIR="${HOME}/cloud/documents"
export XDG_MUSIC_DIR="${HOME}/cloud/music"
export XDG_PICTURES_DIR="${HOME}/cloud/photos"
export XDG_VIDEOS_DIR="${HOME}/cloud/videos"
# On change adjust `${XDG_CONFIG_HOME}/user-dirs.dirs` as well!
export ICONS_PATH="${HOME}/cloud/library/tools/icons/pixelarticons"
# if [ "$(lspci | grep -i geforce)" ]
# then
# export WLR_NO_HARDWARE_CURSORS=1
# fi
# export ANTHROPIC_API_KEY="$(pass show anthropic/api-key)"
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Tmux Magic (via SSH) ║
# ╚════════════════════════════════════════════════════════════════════════════╝
__is_available tmux \
&& [ -n "${SSH_CONNECTION}" ] \
&& [ -z "${TMUX}" ] \
&& [ "${USER}" != "root" ] \
&& tmux new-session -A -s ssh && exit
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ General config ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export HISTCONTROL="ignoredups:ignorespace"
export HISTSIZE="100000"
export HISTFILESIZE="200000"
export SAVEHIST="${HISTSIZE}"
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
export TERM="xterm-256color"
export COLUMNS="80"
# INFO: `nvim` check further down below
export EDITOR="vim"
if [ -n "${SSH_CONNECTION}" ]
then
export BROWSER="w3m"
export OPENER="w3m"
else
export BROWSER="/usr/local/bin/browser"
export OPENER="xdg-open"
fi
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Programs & tools ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export SSH_KEY_PATH="${HOME}/.ssh/id_ed25519"
# Pass
export PASSWORD_STORE_DIR="${HOME}/cloud/library/pass"
# Enable Erlang/IEx shell history
export ERL_AFLAGS="-kernel shell_history enabled"
# IPFS
export IPFS_PATH="${HOME}/.ipfs"
# Firefox
#export GDK_BACKEND="wayland"
export MOZ_ENABLE_WAYLAND="1"
export MOZ_USE_XINPUT2="1"
# Qt
#export QT_STYLE_OVERRIDE="kvantum"
export QT_QPA_PLATFORM="wayland-egl"
export QT_QPA_PLATFORMTHEME="qt5ct"
# https://github.com/oz/tz/
export TZ_LIST="\
Pacific/Honolulu;America/Los_Angeles;\
America/Panama;America/New_York;\
Etc/UTC;Europe/Berlin;\
Asia/Bangkok;Asia/Tokyo;\
Australia/Melbourne;Pacific/Auckland;"
# https://notmuchmail.org/manpages/notmuch-1/
export NOTMUCH_PROFILE="01"
# https://github.com/mrusme/zeit
export ZEIT_DB="${HOME}/cloud/library/tools/zeit.db"
# https://github.com/mrusme/addrb
export ADDRB_DB="${HOME}/.cache/addrb.db"
export ADDRB_TEMPLATE="${HOME}/.config/addrb.tmpl"
# https://github.com/mrusme/caldr
export CALDR_DB="${HOME}/.cache/caldr.db"
export CALDR_TEMPLATE="${HOME}/.config/caldr.tmpl"
# https://github.com/Cloudef/bemenu
export BEMENU_OPTS="-n -c -s -i \
-W 0.3 -H 26 -B 2 -l 10 \
-p '▲' -P '' --ch 16 --scrollbar always \
--fn 'Berkeley Mono 11' \
--nb #040606cc --nf #FFFFFF \
--ab #040606cc --af #FFFFFF \
--hb #72F1B8ff --hf #040606 \
--sb #72F1B8ff --sf #040606 \
--fb #040606cc --ff #FFFFFF \
--fbb #040606cc --fbf #FFFFFF \
--tb #040606cc --tf #FFFFFF \
--scb #040606ff --scf #633affff \
--bdr #72F1B8"
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ ${PATH} ║
# ╚════════════════════════════════════════════════════════════════════════════╝
# LD_LIBRARY_PATH
export LD_LIBRARY_PATH="/usr/local/lib64:$LD_LIBRARY_PATH"
# Cargo (Rust)
[ -d "${HOME}/.cargo/bin" ] \
&& export PATH="${HOME}/.cargo/bin:${PATH}"
[ -e "${HOME}/.cargo/env" ] \
&& source "${HOME}/.cargo/env"
# Go
go env -w GOPATH="${HOME}/.go"
export PATH="$(go env GOPATH)/bin:${PATH}"
export GOPROXY="direct"
export GOTOOLCHAIN=local+auto
# Rubygems
__is_available gem \
&& export PATH="${HOME}/.gem/bin:${PATH}" \
&& export PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin:${PATH}"
# NPM
export NPM_PACKAGES="${HOME}/.local/lib/node_modules"
export PATH="${PATH}:${NPM_PACKAGES}/bin:${HOME}/.local/bin"
export MANPATH="${MANPATH-$(manpath)}:${NPM_PACKAGES}/share/man"
# Wayland
if __is_available sway linux
then
alias sway-launch="dbus-launch --exit-with-session sway"
if test -z "${XDG_RUNTIME_DIR}"
then
export XDG_RUNTIME_DIR="/tmp/${UID}-runtime-dir"
if ! test -d "${XDG_RUNTIME_DIR}"
then
mkdir "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
# GTK_THEME="$(gsettings get org.gnome.desktop.interface gtk-theme)"
GTK_THEME="Windows-95"
export GTK2_RC_FILES="${HOME}/.themes/${GTK_THEME}/gtk-2.0/gtkrc"
fi
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ OMZ ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export ZSH="${HOME}/.oh-my-zsh"
# [ -e ${ZSH} ] || \
# ([ "${USER}" != "root" ] && sh -c "$(curl -fsSL \
# https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)")
__is_available starship \
|| ZSH_THEME="geometry-zsh/geometry"
[ "${USER}" = "root" ] \
&& GEOMETRY_SEPARATOR=" root"
CASE_SENSITIVE="true"
zstyle ':omz:update' mode auto
[ "${USER}" = "root" ] \
&& zstyle ':omz:update' mode disabled
zstyle ':omz:update' frequency 10
zstyle ':omz:update' verbose minimal
DISABLE_LS_COLORS="true"
DISABLE_AUTO_TITLE="false"
ENABLE_CORRECTION="false"
COMPLETION_WAITING_DOTS="false"
DISABLE_UNTRACKED_FILES_DIRTY="false"
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGESTIONS="${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}\
/plugins/zsh-autosuggestions"
ZSH_COMPDUMP="${XDG_CACHE_HOME}/.zcompdump-${HOST}"
zstyle ':omz:*' aliases no
zstyle ':omz:lib:*' aliases no
zstyle ':omz:lib:directories' aliases no
zstyle ':omz:plugins:*' aliases no
# === PLUGINS ===
plugins=(history zsh-autosuggestions fzf aliases)
if [ "${USER}" != "root" ]
then
plugins+=( \
gpg-agent ssh-agent \
genpass git git-extras golang rust gh vi-mode \
rsync mosh pass \
encode64 extract urltools isodate \
)
fi
# === ===
[ -e "${ZSH}/oh-my-zsh.sh" ] \
&& source "${ZSH}/oh-my-zsh.sh"
ZSH_THEME_TERM_TITLE_IDLE='zsh %n@%m:%~'
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Bindkeys ║
# ╚════════════════════════════════════════════════════════════════════════════╝
bindkey '^f' forward-char
bindkey '^[f' forward-word
bindkey '^H' backward-kill-word
# Launch bemenu
__bemenu() { BEMENU_BACKEND=curses bemenu-run; zle redisplay }
zle -N __bemenu
bindkey '^ ' __bemenu
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Aliases ║
# ╚════════════════════════════════════════════════════════════════════════════╝
# https://github.com/zsh-users/zsh/blob/master/Functions/Misc/zmv
alias zmv='noglob zmv -vW'
# https://github.com/ajeetdsouza/zoxide
__is_available zoxide \
&& [ "${USER}" != "root" ] \
&& eval "$(zoxide init --cmd cd zsh)" \
&& alias cdd=cdi
# https://github.com/sharkdp/bat
__is_available bat \
&& alias cat=bat
# https://github.com/eza-community/eza
__is_available eza \
&& alias ls='eza --time-style=relative --git --octal-permissions --icons \
--binary -lg' \
&& alias ll='eza --time-style=long-iso --git --octal-permissions --icons \
--binary -la' \
&& alias la='eza --time-style=long-iso --git --octal-permissions \
--binary --changed -lahHgnuU' \
&& alias l='eza --time-style=long-iso --git --icons \
--binary -l --no-time' \
&& alias lls='eza --time-style=long-iso --git --octal-permissions --icons \
--binary -las modified'
# https://github.com/ClementTsang/bottom
__is_available btm \
&& alias top='btm'
# https://github.com/neomutt/neomutt
__is_available neomutt \
&& alias mutt=neomutt
# https://github.com/neovim/neovim
__is_available nvim \
&& alias vi=nvim \
&& alias vim=nvim \
&& export EDITOR="nvim"
# https://github.com/junegunn/fzf
__is_available fzf \
&& alias preview='fzf --preview="bat {} --color=always"'
# https://github.com/nerdypepper/eva
__is_available eva \
&& alias calc='eva'
# https://github.com/TomNomNom/gron
__is_available gron \
&& alias json='gron'
# https://github.com/sharkdp/hexyl
__is_available hexyl \
&& alias hex='hexyl'
# https://github.com/sharkdp/hyperfine
__is_available hyperfine \
&& alias benchmark='hyperfine'
# https://github.com/irssi/irssi
__is_available irssi \
&& alias irc='irssi'
# https://github.com/kdheepak/taskwarrior-tui
__is_available taskwarrior-tui \
&& alias todo='taskwarrior-tui'
__is_available xdg-open linux \
&& alias open='xdg-open'
__is_available doas linux \
&& alias fucking='doas' \
|| alias fucking='sudo'
alias uuid=uuidgen
alias wget='wget --no-hsts'
alias rmrf='rm -rf'
alias ehco=echo
alias tgz='tar -czf'
alias ugz='tar -xzf'
alias tbz='tar -cjf'
alias ubz='tar -xjf'
alias tailall='tail -f $(find /var/log -type f | grep -v '.gz$')'
alias my-ip="curl http://ipecho.net/plain; echo"
alias element=iamb
# Journal (https://xn--gckvb8fzb.com)
export JRNL="${HOME}/projects/@mrusme/xn--gckvb8fzb.com/content"
alias jrnl="cd ${JRNL}"
alias bookmarks="git -C ${JRNL} checkout develop \
&& vim ${JRNL}/bookmarks/index.md \
&& git -C ${JRNL} add bookmarks \
&& git -C ${JRNL} commit -S"
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ __ __ __ ║
# ║ / // /__ / /__ ___ _______ ║
# ║ / _ / -_) / _ \/ -_) __(_-< ║
# ║ /_//_/\__/_/ .__/\__/_/ /___/ ║
# ║ /_/ ║
# ╚════════════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Mosh/SSH wrapper ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function ssh {
if [ "$2" = "" ]
then
conn="$1"
sshhost=$(printf "%s" "${conn}" | cut -d '@' -f2)
if rg -U -i "^#.*Features:.*mosh.*\nHost ${sshhost}" "${HOME}/.ssh/config" > /dev/null
then
printf "connecting with mosh ...\n"
command mosh ${conn}
else
printf "connecting with ssh ...\n"
command ssh ${conn}
fi
else
printf "connecting with ssh ...\n"
command ssh $@
fi
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Poor-man's aptitude ║
# ╚════════════════════════════════════════════════════════════════════════════╝
if ! __is_available aptitude linux
then
_aptitude()
{
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W \
'install remove purge update upgrade safe-upgrade full-upgrade \
search show clean reinstall' -- "${cur}") )
return 0
}
complete -F "_aptitude" "aptitude"
alias apt='aptitude'
fi
if __is_available emerge linux
then
function aptitude {
if [ -z "$1" ]; then
printf "Usage: aptitude <action> [options] ...\n"
else
case $1 in
install) emerge -av --keep-going=y "${@:2}";;
remove) emerge -cav "${@:2}";;
purge) emerge -Cav "${@:2}";;
update) emerge --sync "${@:2}";;
upgrade) emerge --ask --update --deep --changed-use --verbose-conflicts --keep-going=y "${@[2]:-@world}";;
safe-upgrade)emerge -avu --keep-going=y "${@[2]:-@world}";;
full-upgrade)emerge -avuND --keep-going=y --with-bdeps=y "${@[2]:-@world}";;
search) emerge -s "${@:2}";;
show) equery meta "${@:2}";;
clean) emerge -avc "${@:2}";;
reinstall) emerge -ave "${@:2}";;
*) printf "aptitude: '%s' - unknown action\n" "$1" ;;
esac
fi
}
elif __is_available pacman linux
then
function aptitude {
if [ -z "$1" ]; then
printf "Usage: aptitude <action> [options] ...\n"
else
case $1 in
install) pacman -S "${@:2}";;
remove) pacman -R "${@:2}";;
purge) pacman -Rs "${@:2}";;
update) pacman -Syy "${@:2}";;
upgrade) pacman -Syu "${@:2}";;
safe-upgrade)pacman -Syu "${@:2}";;
full-upgrade)pacman -Syu "${@:2}";;
search) pacman -Ss "${@:2}";;
show) pacman -Si "${@:2}";;
clean) pacman -Scc "${@:2}";;
reinstall) pacman -S "${@:2}";;
*) printf "aptitude: '%s' - unknown action\n" "$1" ;;
esac
fi
}
elif __is_available pkg_add openbsd
then
function aptitude {
if [ -z "$1" ]; then
printf "Usage: aptitude <action> [options] ...\n"
else
case $1 in
install) pkg_add "${@:2}";;
remove) pkg_delete "${@:2}";;
purge) pkg_delete -a "${@:2}";;
update) pkg_add -Uuin "${@:2}";;
upgrade) pkg_add -Uui "${@:2}";;
safe-upgrade)sysupgrade;;
full-upgrade)sysupgrade;;
search) pkg_info -Q "${@:2}";;
show) pkg_info "${@:2}";;
clean) pkg_check "${@:2}";;
reinstall) pkg_add -Uui "${@:2}";;
*) printf "aptitude: '%s' - unknown action\n" "$1" ;;
esac
fi
}
fi
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Gentoo packages helper ║
# ╚════════════════════════════════════════════════════════════════════════════╝
if __is_available equery
then
function __packages_list() {
case "$1" in
nongentoo)
eselect --brief repository list -i \
| awk '{ print $1 }' \
| while read -r repo; \
do
[ "$repo" != "gentoo" ] && equery has repository "$repo"; \
done
;;
9999)
equery list '*' | rg '\-9999'
;;
*)
printf "unknown: %s\n" "$1"
;;
esac
}
function packages() {
case "$1" in
list) __packages_list "${@:2}";;
esac
}
fi
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ update-tools ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function update-tools() {
printf "Updating Rust tools ...\n"
cargo install-update -a -g
printf "\nUpdating Go tools ...\n"
unset GOPROXY
/bin/ls -1 ~/.go/bin/ \
| while read -r bin; do go version -m "${HOME}/.go/bin/${bin}" \
| grep '^[[:space:]]path' \
| awk '{ print $2 }' \
| grep '^github.com' \
| sort \
| uniq \
| xargs -I{} go install {}@latest; done
printf "\nUpdating NPM tools ...\n"
npm update -g
printf "\nUpdating gh extensions ...\n"
gh extension upgrade --all
printf "\nUpdating vale ...\n"
vale sync
printf "\nUpdating tealdeer ...\n"
tldr --update
printf "\nUpdating Zsh plugins ...\n"
git -C ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions pull
git -C ~/.oh-my-zsh/themes/geometry-zsh pull
printf "\nTools updated"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Radicle ║
# ╚════════════════════════════════════════════════════════════════════════════╝
autoload -U zmv add-zsh-hook
__rad_checker() {
emulate -L zsh
if [ -d .git/refs/remotes/rad/ ]
then
rad auth
fi
}
add-zsh-hook chpwd __rad_checker
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Git ║
# ╚════════════════════════════════════════════════════════════════════════════╝
alias ga='git add'
alias ga.='ga .'
alias gb='git branch'
alias gc='git commit --verbose'
alias 'gc!'='git commit --verbose --amend'
alias gcs='git commit --gpg-sign'
alias 'gcs!'='git commit --verbose --gpg-sign --amend'
alias gcss='git commit --gpg-sign --signoff'
alias 'gcss!'='git commit --verbose --gpg-sign --signoff --amend'
alias gcb='git checkout -b'
alias gco='git checkout'
alias gcor='git checkout --recurse-submodules'
alias gcl='git clone --recurse-submodules'
alias gd='git diff'
alias gds='git diff --staged'
alias gf='git fetch'
alias gfa='git fetch --all --prune --jobs=10'
alias gl='git pull'
alias gp='git remote \
| xargs -I R git push R "$(git_current_branch)"'
alias gpa='git remote \
| xargs -I R git push R --all'
alias gpat='git remote \
| xargs -I R git push R --all && git remote \
| xargs -I R git push R --tags'
alias 'gpfat!'='git remote \
| xargs -I R git push R --all --force && git remote \
| xargs -I R git push R --tags --force'
alias 'gpf!'='git remote \
| xargs -I R git push R --all --force'
alias gpoat='echo "Deprecated, use gpat"'
alias 'gpoat!'='echo "Deprecated, use gpfat!"'
alias grb='git rebase'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias gm='git merge'
alias gma='git merge --abort'
alias gmc='git merge --continue'
alias gsb='git status --short --branch'
alias gts='git tag --sign'
# git tag delete
gtd() {
git tag -d "$1"
git remote | while read -r remote; do git push --delete "${remote}" "$1"; done
}
alias git-crypt-add-myself="git-crypt add-gpg-user \
4D3899AF73E7F5FE9B39C822272ED814BF63261F"
function git-find-modified-repos() {
find ./ -type d -name '.git' | while read -r dir
do
repo=$(dirname "${dir}")
repostatus=$(git -C "${repo}" status -s)
if [ -n "${repostatus}" ]
then
printf "%s\n" "${repo}"
fi
done
}
# github checkout issue
function ghcoi() {
if [ "$1" = "" ]
then
printf "usage: %s <issue number>\n" "$0"
exit 1
fi
git checkout -b "$1-$(gh issue view "$1" --json title \
| jq --raw-output '.title' \
| iconv -t ascii//TRANSLIT \
| sed -E 's/[^a-zA-Z0-9]+/-/g' \
| sed -E 's/^-+|-+$//g' \
| tr '[:upper:]' '[:lower:]')"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ What's ... ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function whats() {
if ! __is_available units || ! __is_available whatis
then
printf "This command requires units(1) and whatis(1)!\n"
return 1
fi
value=""
value_unit=""
from_unit=""
to=""
to_unit=""
_in=""
_in_unit=""
if [ "$#" -eq "1" ]
then
if [ "$1" = "love" ]
then
printf "... got to do, got to do with it?\n"
return 0
else
whatis "$1"
return "$?"
fi
elif [ "$#" -eq "2" ]
then
value_unit="$1"
to_unit="$2"
elif [ "$#" -eq "3" ]
then
if [ "$2" = "to" ] || [ "$2" = "in" ] || [ "$2" = "of" ]
then
value_unit="$1"
to="$2"
to_unit="$3"
else
value="$1"
from_unit="$2"
to_unit="$3"
fi
elif [ "$#" -eq "4" ]
then
value="$1"
from_unit="$2"
to="$3"
to_unit="$4"
elif [ "$#" -eq "5" ]
then
value="$1"
from_unit=""
to="$2"
to_unit="$3"
_in="$4"
_in_unit="$5"
else
printf "usage: %s <value>[[ ]unit] [to/in|of] <to/in unit/value|of value> [in %%]\n" "$0"
printf "\n"
printf "examples:\n"
printf "\n"
printf " %s 20 kmh in mph\n" "$0"
printf " %s 3 cups in ml\n" "$0"
printf " %s 6ft to m\n" "$0"
printf " %s 10%% of 120\n" "$0"
printf " %s 10 of 200 in %%\n" "$0"
printf " %s 10 to 100 in %%\n" "$0"
printf "\n"
return 1
fi
if [ "${value_unit}" != "" ]
then
combined="$(printf "%s" "${value_unit}" | grep -Eo '[[:alpha:]\$\%]+|[0-9]+')"
value="$(printf "%s" "${combined}" | head -n 1)"
from_unit="$(printf "%s" "${combined}" | tail -n 1)"
fi
from_unit=$(printf "%s" "${from_unit}" | tr '[:upper:]' '[:lower:]')
to_unit=$(printf "%s" "${to_unit}" | tr '[:upper:]' '[:lower:]')
units_from="${value}${from_unit}"
units_to="${to_unit}"
case "${from_unit}" in
"f")
units_from="tempF(${value})"
;;
"c")
units_from="tempC(${value})"
;;
"kmh")
units_from="${value} km/hour"
;;
esac
case "${to_unit}" in
"f")
units_to="tempF"
;;
"c")
units_to="tempC"
;;
"kmh")
units_to="km/hour"
;;
esac
if [ "${from_unit}" = "%" ]
then
eva "(${value} / 100) * ${units_to}" | tr -d ' '
return "$?"
elif [ "${_in}" != "" ] && [ "${_in_unit}" = "%" ]
then
if [ "${to}" = "of" ]
then
eva "(${value} / ${to_unit}) * 100" | tr -d ' '
return "$?"
elif [ "${to}" = "to" ]
then
eva "((${to_unit} - ${value}) / ${value}) * 100" | tr -d ' '
return "$?"
fi
else
units --compact -1 "${units_from}" "${units_to}"
return "$?"
fi
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Online tools ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function jitsi-link() {
url=$(printf "https://meet.jit.si/%s" "$(uuidgen)")
printf "%s" "${url}" | wl-copy
printf "%s\n" "${url}"
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Multimedia ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function video-to-gif() {
fps="$3"
if [[ "$3" == "" ]];
then
fps="10"
fi
ffmpeg \
-i "$1" \
-filter_complex \
"[0:v]setpts=0.5*PTS,fps=$fps,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-filter:a 'atempo=1,atempo=1' \
-loop 0 \
"$2"
}
function rip() {
yt-dlp \
-f bestaudio \
--extract-audio \
--audio-format mp3 \
--audio-quality 0 \
--yes-playlist \
--add-metadata \
"$1"
}
function listen() {
url="$1"
if [ "$1" = "to" ]
then
url="$2"
fi
mpv \
--quiet \
--no-video \
"$url"
}
function scale-and-crop() {
find ./ \
-type f \
-iname '*.jpg' \
-exec identify -format '%w %h %i\n' '{}' \; \
| awk '{ if($1 < $2) { system("convert " $3 " -resize 2160x " $3); system("convert " $3 " -crop 2160x3840+0+0 " $3) } else { system("convert " $3 " -resize 3840x " $3); system("convert " $3 " -crop 3840x2160+0+0 " $3) }}'
}
function compress-all-jpgs() {
find ./ \
-iname '*.jpg' \
-type f \
-size +2M \
-exec imager -f jpeg -i "{}" -o "{}" \;
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ addrb (https://github.com/mrusme/addrb) ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function addrb() {
match=$(echo "$*" | grep -o '\-r')
if [ "$match" != "" ]
then
export CARDDAV_USERNAME="$(pass show dav/username)"
export CARDDAV_PASSWORD="$(pass show dav/password)"
export CARDDAV_ENDPOINT="$(pass show dav/endpoint)"
fi
command addrb $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ caldr (https://github.com/mrusme/caldr) ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function caldr() {
match=$(echo "$*" | grep -o '\-r')
if [ "$match" != "" ]
then
export CARDDAV_USERNAME="$(pass show dav/username)"
export CARDDAV_PASSWORD="$(pass show dav/password)"
export CARDDAV_ENDPOINT="$(pass show dav/endpoint)"
fi
command caldr $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ planor (https://github.com/mrusme/planor) ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function planor() {
export VULTR_API_KEY="$(pass show vultr/token)"
export RENDER_API_TOKEN="$(pass show render/token)"
export FLEEK_API_TOKEN="$(pass show fleek/token)"
export FLEEK_TEAM_ID="$(pass show fleek/team)"
command planor $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ conclusive (https://github.com/mrusme/conclusive) ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function conclusive() {
export PLAUSIBLE_TOKEN="$(pass show plausible/token)"
command conclusive $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ gh ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function gh() {
export GITHUB_TOKEN="$(pass show github/token)"
command gh $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ mods ║
# ╚════════════════════════════════════════════════════════════════════════════╝
function mods() {
export OPENAI_API_KEY="$(pass show openai/apikey)"
command mods $@
}
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ Dotfiles management ║
# ╚════════════════════════════════════════════════════════════════════════════╝
export DOTFILES="${HOME}/projects/@mrusme/dotfiles"