-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zshrc
2198 lines (1833 loc) · 69.9 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
#!/usr/bin/env zsh
# shellcheck shell=bash
DOTFILES_PATH="${HOME}/src/miscellaneous"
config_help=false
config_benchmark=false
if [[ -z "$zshrc_low_power" ]]; then
# Allow low power mode to propagte up TMUX.
zshrc_low_power=false
fi
zshrc_dropping_mode=false
zshrc_benchmark_start() {
if ( $config_benchmark ); then
zmodload zsh/zprof
fi
}
zshrc_benchmark_stop() {
if ( $config_benchmark ); then
zprof > "${HOME}/.zprof.log"
echo "ZSH profiling log saved to ${HOME}/.zprof.log"
fi
}
zshrc_probe() {
case $TERM in
*linux*)
export zshrc_low_power=true
echo "Low power mode enabled."
;;
*vt100*)
export zshrc_low_power=true
echo "Low power mode enabled."
;;
esac
}
zshrc_enter_tmux() {
if [[ -n "$(command -v tmux)" ]]; then
local session_count=$(tmux ls 2>/dev/null | wc -l)
if type tmuxp > /dev/null 2>&1; then
if [[ -z "$TMUX" ]]; then
# If we haven't entered tmux yet, then load the tmuxp
# configuration for the current host, and attach if it already
# exists.
local host_config="${HOME}/.tmuxp/$(hostname).yaml"
if [ -s "${host_config}" ]; then
tmuxp load -y "${host_config}"
else
tmuxp load -y "${HOME}/.tmuxp/main.yaml"
fi
elif [[ -n "$TMUX" ]]; then
# If we are already in a tmux session, just display the banner for this shell.
zshrc_display_banner
fi
else
local session_count=$(tmux ls 2>/dev/null | wc -l)
if [[ "$session_count" -eq "0" ]]; then
tmux -2 new-session -s "Main"
else
# Make sure we are not already in a tmux session
if [[ -z "$TMUX" ]]; then
# Session id is date and time to prevent conflict
# TODO: Make session number more... meaningful?
local session_id="$(date +%H%M%S)"
# Create a new session (without attaching it) and link to base session
# to share windows
tmux -2 new-session -d -t Main -s "$session_id"
# Attach to the new session & kill it once orphaned
tmux -2 attach-session -t "$session_id" \; set-option destroy-unattached
else
zshrc_display_banner
fi
fi
fi
else
zshrc_display_banner
fi
}
# Adapted from oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/termsupport.zsh
zshrc_auto_window_title() {
if [ -z "$DISABLE_AUTO_TITLE" ]; then
DISABLE_AUTO_TITLE=false
fi
function title {
emulate -L zsh
setopt prompt_subst
[[ "$EMACS" == *term* ]] && return
# if $2 is unset use $1 as default
# if it is set and empty, leave it as is
: ${2=$1}
case "$TERM" in
cygwin|xterm*|putty*|rxvt*|ansi)
if [[ "$TMUX_PANE" == "%0" || "$TMUX_PANE" == "%1" ]]; then
print -Pn "\ekSYS\e\\" # set screen hardstatus
elif [[ "$TMUX_PANE" == "%2" || "$TMUX_PANE" == "%3" ]]; then
print -Pn "\ekCOM\e\\" # set screen hardstatus
else
print -Pn "\e]2;$2:q\a" # set window name
print -Pn "\e]1;$1:q\a" # set tab name
fi
;;
screen*|tmux*)
if [[ "$TMUX_PANE" == "%0" || "$TMUX_PANE" == "%1" ]]; then
print -Pn "\ekSYS\e\\" # set screen hardstatus
elif [[ "$TMUX_PANE" == "%2" || "$TMUX_PANE" == "%3" ]]; then
print -Pn "\ekCOM\e\\" # set screen hardstatus
else
print -Pn "\ek$1:q\e\\" # set screen hardstatus
fi
;;
*)
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
print -Pn "\e]2;$2:q\a" # set window name
print -Pn "\e]1;$1:q\a" # set tab name
else
# Try to use terminfo to set the title
# If the feature is available set title
if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
echoti tsl
print -Pn "$1"
echoti fsl
fi
fi
;;
esac
}
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
# Avoid duplication of directory in terminals with independent dir display
if [[ "$TERM_PROGRAM" == Apple_Terminal ]]; then
ZSH_THEME_TERM_TITLE_IDLE="%n@%m"
fi
# Runs before showing the prompt
function omz_termsupport_precmd {
emulate -L zsh
if [[ "$DISABLE_AUTO_TITLE" == true ]]; then
return
fi
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
}
# Runs before executing the command
function omz_termsupport_preexec {
emulate -L zsh
setopt extended_glob
if [[ "$DISABLE_AUTO_TITLE" == true ]]; then
return
fi
# cmd name only, or if this is sudo or ssh, the next cmd
local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
local LINE="${2:gs/%/%%}"
title '$CMD' '%100>...>$LINE%<<'
}
precmd_functions+=(omz_termsupport_precmd)
preexec_functions+=(omz_termsupport_preexec)
# Keep Apple Terminal.app's current working directory updated
# Based on this answer: https://superuser.com/a/315029
# With extra fixes to handle multibyte chars and non-UTF-8 locales
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
# Emits the control sequence to notify Terminal.app of the cwd
# Identifies the directory using a file: URI scheme, including
# the host name to disambiguate local vs. remote paths.
function update_terminalapp_cwd() {
emulate -L zsh
# Percent-encode the pathname.
local URL_PATH="$(omz_urlencode -P $PWD)"
[[ $? != 0 ]] && return 1
# Undocumented Terminal.app-specific control sequence
printf '\e]7;%s\a' "file://$HOST$URL_PATH"
}
# Use a precmd hook instead of a chpwd hook to avoid contaminating output
precmd_functions+=(update_terminalapp_cwd)
# Run once to get initial cwd set
update_terminalapp_cwd
fi
}
# Adapted from oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/completion.zsh
zshrc_setup_completion() {
# zstyle ':completion:*' auto-description '\ %d'
# Removed: _list
# Was ruining menucomplete
# zstyle ':completion:*' completer _expand _complete _ignored _match _correct _approximate _prefix
# zstyle ':completion:*' format '> Completing %d ...'
# zstyle ':completion:*' insert-unambiguous true
# shellcheck disable=SC2296
zstyle ":completion:*:default" list-colors ${(s.:.)LS_COLORS}
# zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
# zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'l:|=* r:|=*'
# zstyle ':completion:*' max-errors 4
# zstyle ':completion:*' menu select=1
# zstyle ':completion:*' original true
# zstyle ':completion:*' preserve-prefix '//[^/]##/'
# zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' squeeze-slashes true
# zstyle ':completion:*' verbose true
# zstyle ':completion:*' rehash true
# Partial completions: ~/L/P/B -> ~/Library/Preferences/ByHost
zstyle ':completion:*' list-suffixes
zstyle ':completion:*' expand prefix suffix
# Makefile completion
zstyle ':completion:*:make:*:targets' call-command true # outputs all possible results for make targets
zstyle ':completion:*:make:*' tag-order targets
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '%B%d%b'
zmodload -i zsh/complist
WORDCHARS=''
unsetopt menu_complete # do not autoselect the first completion entry
unsetopt flowcontrol
setopt auto_menu # show completion menu on successive tab press
setopt complete_in_word
setopt always_to_end
setopt shwordsplit # https://unix.stackexchange.com/questions/19530/expanding-variables-in-zsh
# should this be in keybindings?
bindkey -M menuselect '^o' accept-and-infer-next-history
zstyle ':completion:*:*:*:*:*' menu select
# case insensitive (all), partial-word and substring completion
# if [[ "$CASE_SENSITIVE" = true ]]; then
# zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*'
# else
# if [[ "$HYPHEN_INSENSITIVE" = true ]]; then
zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'
# else
# zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
# fi
# fi
# unset CASE_SENSITIVE HYPHEN_INSENSITIVE
# Complete . and .. special directories
zstyle ':completion:*' special-dirs true
# zstyle ':completion:*' list-colors ''
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
# if [[ "$OSTYPE" = solaris* ]]; then
# zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm"
# else
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
# fi
# disable named-directories autocompletion
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
# Use caching so that commands like apt and dpkg complete are useable
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path $ZSH_CACHE_DIR
# Don't complete uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \
adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \
clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \
gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \
ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \
named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \
operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \
rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \
usbmux uucp vcsa wwwrun xfs '_*'
# ... unless we really want to.
zstyle '*' single-ignored show
# Complete IP addresses from host files.
zstyle ':completion:*' use-ip true
# if [[ $COMPLETION_WAITING_DOTS = true ]]; then
expand-or-complete-with-dots() {
# toggle line-wrapping off and back on again
[[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti rmam
print -Pn "%{%F{red}......%f%}"
[[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti smam
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey "^I" expand-or-complete-with-dots
# fi
zstyle :compinstall filename '~/.zshrc'
if type rustup > /dev/null 2>&1; then
if [[ ! -s "${HOME}/.zsh_completions/_rustup" ]]; then
rustup completions zsh > "${HOME}/.zsh_completions/_rustup"
fi
if type cargo > /dev/null 2>&1 && [[ ! -s "${HOME}/.zsh_completions/_cargo" ]]; then
rustup completions zsh cargo > "${HOME}/.zsh_completions/_cargo"
fi
fi
# Load `awscli`'s completions if available.
# NOTE: These are bash completions!
local aws_completer_path="$(command -v aws_completer)"
if [ -x $aws_completer_path ]; then
complete -C "$aws_completer_path" aws
fi
if type gh > /dev/null 2>&1; then
if [[ ! -s "${HOME}/.zsh_completions/_gh" ]]; then
gh completion -s zsh > "${HOME}/.zsh_completions/_gh"
fi
fi
if type activate-global-python-argcomplete > /dev/null 2>&1; then
if [[ ! -s "${HOME}/.zsh_completions/_python-argcomplete" ]]; then
activate-global-python-argcomplete --dest "${HOME}/.zsh_completions/"
fi
fi
if type rg > /dev/null 2>&1; then
if [ ! -s "${HOME}/.zsh_completions/_rg" ]; then
rg --generate=complete-zsh > "${HOME}/.zsh_completions/_rg"
fi
fi
if type helm > /dev/null 2>&1; then
if [ ! -s "${HOME}/.zsh_completions/_helm" ]; then
helm completion zsh > "${HOME}/.zsh_completions/_helm"
fi
fi
if type docker > /dev/null 2>&1; then
if [ ! -s "${HOME}/.zsh_completions/_docker" ]; then
docker completion zsh > "${HOME}/.zsh_completions/_docker"
fi
fi
#if type pipx > /dev/null 2>&1; then
#if [ ! -s "${HOME}/.zsh_completions/_pipx" ]; then
#register-python-argcomplete pipx > "${HOME}/.zsh_completions/_pipx"
#fi
#fi
# Takes a lot of extra time ...
#if type molecule > /dev/null 2>&1; then
# Because it may be in a venv, we will have to do this on-demand.
#eval "$(_MOLECULE_COMPLETE=zsh_source molecule)"
#if [ ! -s "${HOME}/.zsh_completions/_molecule" ]; then
#_MOLECULE_COMPLETE=zsh_source molecule > "${HOME}/.zsh_completions/_molecule"
#fi
#fi
}
zshrc_autoload() {
# Used to debug the fpath variable.
pretty_fpath() {
old_IFS=$IFS # Save the current IFS (Internal Field Separator)
IFS=' ' # Set the delimiter to ':'
# shellcheck disable=SC2086
set -- $fpath # Split PATH into positional parameters
IFS=$old_IFS # Restore the original IFS
echo "Precedence order of directories in fpath:"
index=1
while [ $# -gt 0 ]; do
dir=$1
shift
if [ -n "$dir" ]; then
echo "$index) $dir"
index=$((index + 1))
fi
done
}
# Setup the ZSH completions directory before we initialize completions.
mkdir -p "${HOME}/.zsh_completions"
fpath+="${HOME}/.zsh_completions"
if type brew > /dev/null 2>&1; then
fpath+="$(brew --prefix)/share/zsh/site-functions"
fi
if [ -d "/usr/share/zsh/functions/Completion/Unix" ]; then
fpath+="/usr/share/zsh/functions/Completion/Unix"
fi
if [ -d "/usr/share/zsh/vendor-completions" ]; then
fpath+="/usr/share/zsh/vendor-completions"
fi
autoload -Uz compinit && compinit
autoload -Uz bashcompinit && bashcompinit # TODO: I don't think this is working right.
autoload -Uz promptinit && promptinit
autoload -Uz add-zsh-hook
autoload -Uz edit-command-line
if ( $config_help ); then
autoload -Uz run-help
alias help=run-help
autoload -Uz run-help-git
autoload -Uz run-help-ip
autoload -Uz run-help-openssl
autoload -Uz run-help-p4
autoload -Uz run-help-sudo
autoload -Uz run-help-svk
autoload -Uz run-help-svn
fi
}
zshrc_source() {
# NOTE: This will append a path which points to a fzf binary which is
# provided outside of the package manager. This is ideal behavior because
# it offers preference to a distribution managed fzf binary.
if [ -f "${HOME}/.zplug/repos/junegunn/fzf/shell/key-bindings.zsh" ]; then
# fzf searches for this, so leave it as it is.
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
fi
if [[ -e "$HOME/src/robobenklein-config/zsh/plunks/rtabfunc.zsh" ]]; then
source "$HOME/src/robobenklein-config/zsh/plunks/rtabfunc.zsh"
fi
if [ -s "$HOME/.luaver/luaver" ]; then
source "$HOME/.luaver/luaver"
fi
if [ -n "${PYENV_ROOT}" ]; then
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
}
zshrc_set_options() {
HISTFILE=~/.histfile
# The average command is 20.092 characters long.
HISTSIZE=10000 # How much is saved to file.
SAVEHIST=10000 # How much is kept in memory.
# man zshoptions
setopt correct
#setopt correctall
setopt clobber
setopt interactivecomments
setopt nomatch
setopt extendedglob
setopt listpacked
setopt menucomplete
setopt sharehistory
setopt appendhistory
setopt autocd
setopt beep
setopt notify
# Vim Bindings
bindkey -v
bindkey '^a' beginning-of-line
bindkey '^e' end-of-line
bindkey '^P' up-history
bindkey '^N' down-history
bindkey '^h' backward-delete-char
bindkey '^w' backward-kill-word
bindkey '^r' history-incremental-search-backward
bindkey '^[[Z' reverse-menu-complete
zle-keymap-select () {
zle reset-prompt
zle -R
}
zle -N zle-keymap-select
export KEYTIMEOUT=1
}
zshrc_powerlevel9k() {
POWERLEVEL9K_MODE="nerdfont-complete"
POWERLEVEL9K_PROMPT_ON_NEWLINE=false
#POWERLEVEL9K_RPROMPT_ON_NEWLINE=false
# Intriguing elements:
# detect_virt
# Featureful but slow variant:
# POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(time context ip load ram_joined battery_joined vcs newline os_icon ssh vi_mode dir dir_writable)
# POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(background_jobs command_execution_time)
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(time virtualenv vcs newline os_icon ssh dir dir_writable)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(background_jobs command_execution_time)
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX=""
POWERLEVEL9K_MULTILINE_NEWLINE_PROMPT_PREFIX=""
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX=""
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=5
POWERLEVEL9K_VI_INSERT_MODE_STRING="I"
POWERLEVEL9K_VI_COMMAND_MODE_STRING="N"
POWERLEVEL9K_SHORTEN_DIR_LENGTH=3
POWERLEVEL9K_SHORTEN_DELIMITER=""
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right"
# Colors
POWERLEVEL9K_COLOR_SCHEME="dark"
PL9K_TEXT_COLOR="232"
PL9K_TEXT_INVERSE_COLOR="255"
PL9K_BLUE="033"
# PL9K_BLUE="075"
# PL9K_GREEN="046"
PL9K_GREEN="071"
# PL9K_RED="196"
PL9K_RED="202"
# PL9K_ORANGE="214"
PL9K_ORANGE="172"
POWERLEVEL9K_TIME_BACKGROUND="255"
POWERLEVEL9K_TIME_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_DETECT_VIRT_BACKGROUND="249"
POWERLEVEL9K_DETECT_VIRT_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND="246"
POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_CONTEXT_SUDO_BACKGROUND="246"
POWERLEVEL9K_CONTEXT_SUDO_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_CONTEXT_REMOTE_BACKGROUND="246"
POWERLEVEL9K_CONTEXT_REMOTE_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_CONTEXT_REMOTE_SUDO_BACKGROUND="246"
POWERLEVEL9K_CONTEXT_REMOTE_SUDO_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_CONTEXT_ROOT_BACKGROUND="246"
POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND="${PL9K_RED}"
POWERLEVEL9K_IP_BACKGROUND="243"
POWERLEVEL9K_IP_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_LOAD_NORMAL_BACKGROUND="240"
POWERLEVEL9K_LOAD_NORMAL_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_LOAD_WARNING_BACKGROUND="240"
POWERLEVEL9K_LOAD_WARNING_FOREGROUND="${PL9K_ORANGE}"
POWERLEVEL9K_LOAD_CRITICAL_BACKGROUND="240"
POWERLEVEL9K_LOAD_CRITICAL_FOREGROUND="${PL9K_RED}"
POWERLEVEL9K_RAM_BACKGROUND="240"
POWERLEVEL9K_RAM_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_BATTERY_CHARGED_BACKGROUND="240"
POWERLEVEL9K_BATTERY_CHARGED_FOREGROUND="${PL9K_TEXT_INVERSE_COLOR}"
POWERLEVEL9K_BATTERY_DISCONNECTED_BACKGROUND="240"
POWERLEVEL9K_BATTERY_DISCONNECTED_FOREGROUND="${PL9K_BLUE}"
POWERLEVEL9K_BATTERY_CHARGING_BACKGROUND="240"
POWERLEVEL9K_BATTERY_CHARGING_FOREGROUND="${PL9K_GREEN}"
POWERLEVEL9K_BATTERY_LOW_BACKGROUND="240"
POWERLEVEL9K_BATTERY_LOW_FOREGROUND="${PL9K_RED}"
POWERLEVEL9K_VIRTUALENV_BACKGROUND="240"
POWERLEVEL9K_VIRTUALENV_FOREGROUND="${PL9K_TEXT_INVERSE_COLOR}"
POWERLEVEL9K_VCS_CLEAN_BACKGROUND="237"
POWERLEVEL9K_VCS_CLEAN_FOREGROUND="${PL9K_TEXT_INVERSE_COLOR}"
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND="237"
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND="${PL9K_BLUE}"
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND="237"
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND="${PL9K_GREEN}"
POWERLEVEL9K_OS_ICON_BACKGROUND="252"
POWERLEVEL9K_OS_ICON_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_SSH_BACKGROUND="243"
POWERLEVEL9K_SSH_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_VI_MODE_NORMAL_BACKGROUND="237"
POWERLEVEL9K_VI_MODE_NORMAL_FOREGROUND="${PL9K_BLUE}"
POWERLEVEL9K_VI_MODE_INSERT_BACKGROUND="237"
POWERLEVEL9K_VI_MODE_INSERT_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_DIR_DEFAULT_BACKGROUND="234"
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND="${PL9K_TEXT_INVERSE_COLOR}"
POWERLEVEL9K_DIR_HOME_BACKGROUND="234"
POWERLEVEL9K_DIR_HOME_FOREGROUND="${PL9K_TEXT_INVERSE_COLOR}"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND="234"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND="${PL9K_TEXT_INVERSE_COLOR}"
POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_BACKGROUND="243"
POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_FOREGROUND="${PL9K_RED}"
if (( ${+functions[rtab]} )); then
# POWERLEVEL9K_CUSTOM_RTAB_DIR="echo \${RTAB_PWD}"
POWERLEVEL9K_CUSTOM_RTAB_DIR="echo \$(rtab -l -t)"
POWERLEVEL9K_CUSTOM_RTAB_DIR_FOREGROUND="${POWERLEVEL9K_DIR_DEFAULT_FOREGROUND}"
POWERLEVEL9K_CUSTOM_RTAB_DIR_BACKGROUND="${POWERLEVEL9K_DIR_DEFAULT_BACKGROUND}"
# TODO: Make this dynamically replace dir with custom_rtab_dir
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(time vcs newline os_icon ssh custom_rtab_dir dir_writable)
# typeset -a chpwd_functions
# chpwd_functions+=(_rtab_pwd_update)
# function _rtab_pwd_update() {
# export RTAB_PWD=$(rtab -l -t)
# }
# _rtab_pwd_update
fi
# typeset -gA p10k_opts
# p10k_opts=(
# p10ks_cwd ';;;;rtab;-t;-l'
# )
POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND="240"
POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND="${PL9K_TEXT_COLOR}"
POWERLEVEL9K_BACKGROUND_JOBS_BACKGROUND="237"
POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND="${PL9K_TEXT_COLOR}"
if ( $zshrc_low_power ); then
POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR=$']'
POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR=$'['
fi
}
zshrc_raw_prompt() {
prompt adam2
}
zshrc_zplug() {
if [[ ! -d "$HOME/.zplug" ]]; then
curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh
fi
if [[ -d "$HOME/.zplug" ]]; then
source "$HOME/.zplug/init.zsh"
zplug "zplug/zplug", hook-build: "zplug --self-manage"
zplug "zsh-users/zsh-history-substring-search"
zplug "zsh-users/zsh-autosuggestions"
zplug "zsh-users/zsh-completions"
zplug "mfaerevaag/wd", as:command, use:"wd.sh", hook-load:"wd() { . $ZPLUG_REPOS/mfaerevaag/wd/wd.sh }"
# For some reason, the hook doesn't always work...
wd() {
. $ZPLUG_REPOS/mfaerevaag/wd/wd.sh
}
# Add zsh completion for this plugin.
if [[ -d "${HOME}/.zplug/repos/mfaerevaag/wd/" ]]; then
fpath+="${HOME}/.zplug/repos/mfaerevaag/wd/"
fi
zplug "arzzen/calc.plugin.zsh"
zplug "chrissicool/zsh-256color"
zplug "hlissner/zsh-autopair", defer:2
# Improved bash compatibility
# zplug "chrissicool/zsh-bash"
#zplug "stackexchange/blackbox"
zplug "tarrasch/zsh-command-not-found"
zplug "junegunn/fzf", as:command, rename-to:fzf, \
hook-build:"rm ~/.fzf.zsh; ./install --all && source ${HOME}/.fzf.zsh"
# Install fzf or fzy
zplug "b4b4r07/enhancd", use:init.sh, hook-load:"ENHANCD_ENABLE_DOUBLE_DOT=false"
# git log = glo; git diff = gd; git add = ga; git ignore = gi
zplug "wfxr/forgit", defer:1
export NVM_LAZY_LOAD=true
export NVM_CACHE_LOAD=true
# zplug "lukechilds/zsh-nvm"
zplug "maxattax97/zsh-nvm"
zplug "gko/ssh-connect", as:command, use:"ssh-connect.sh", hook-load:". $ZPLUG_REPOS/gko/ssh-connect/ssh-connect.sh"
alias sshc='ssh-connect'
if ( ! "$zshrc_low_power" ); then
#zplug "bhilburn/powerlevel9k", at:master, use:powerlevel9k.zsh-theme
zplug "romkatv/powerlevel10k", as:theme, depth:1
fi
# zplug "ael-code/zsh-colored-man-pages"
# zplug "supercrabtree/k"
# zplug "psprint/zsh-navigation-tools" # deleted
# zplug "z-shell/zsh-navigation-tools" # alternate
zplug "zdharma-continuum/zsh-navigation-tools"
# Must load last.
# zplug "zsh-users/zsh-syntax-highlighting"
# zplug "zdharma/fast-syntax-highlighting", defer:3
zplug "zdharma-continuum/fast-syntax-highlighting", defer:3
# Really annoying and doesn't seem to work right?
#zplug "hkupty/ssh-agent"
zplug "plugins/thefuck", from:oh-my-zsh
bindkey "^f" fuck-command-line
zplug "MichaelAquilina/zsh-autoswitch-virtualenv"
if ! zplug check; then
zplug install
fi
zplug load
else
echo "Failed to load zplug plugins."
fi
}
zshrc_extensions() {
if type navi > /dev/null 2>&1; then
eval "$(navi widget zsh)"
fi
if type keychain > /dev/null 2>&1; then
eval "$(keychain --eval -q)"
fi
#if [[ -z "${SSH_AGENT_PID}" ]]; then
#eval $(ssh-agent -t 10m) 1>/dev/null
# Add a key:
# ssh-add ~/.ssh/id_rsa
# List currently loaded keys:
# ssh-add -L
#fi
}
zshrc_display_banner() {
if ( ! "$zshrc_low_power" ); then
if type fastfetch > /dev/null 2>&1; then
fastfetch
elif type neofetch > /dev/null 2>&1; then
neofetch --disable "packages"
elif type screenfetch > /dev/null 2>&1; then
screenfetch -d '-pkgs,wm,de,res,gtk;+disk' -E
echo
fi
if type mikaelasay > /dev/null 2>&1 && [[ "$CHASSIS" != "laptop" ]]; then
mikaelasay
echo
fi
else
echo "Entering low power mode ..."
echo
fi
}
# Prepend or postpend a path to the $PATH variable if it exists and is not
# already in the $PATH. This is a derivative of POSIX shell's pathmunge
# (usually found in /etc/profile)
zshrc_add_path() {
if [ -d "$1" ]; then
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
# Includes "before" and is the default
PATH=$1:$PATH
fi
esac
fi
}
zshrc_set_path() {
# Used to debug the PATH variable.
pretty_path() {
old_IFS=$IFS # Save the current IFS (Internal Field Separator)
IFS=':' # Set the delimiter to ':'
# shellcheck disable=SC2086
set -- $PATH # Split PATH into positional parameters
IFS=$old_IFS # Restore the original IFS
echo "Precedence order of directories in PATH:"
index=1
while [ $# -gt 0 ]; do
dir=$1
shift
if [ -n "$dir" ]; then
echo "$index) $dir"
index=$((index + 1))
fi
done
}
if [ -s "${HOME}/.profile" ]; then
echo "Your profile is not empty and is being sourced!"
fi
if [ -s "${HOME}/.zshenv" ]; then
echo "Your .zshenv is not empty and is being sourced!"
fi
# The sbin paths are processed after the general bin paths.
zshrc_add_path "/usr/local/bin" after
zshrc_add_path "/usr/local/sbin" after
zshrc_add_path "/usr/bin" after
zshrc_add_path "/usr/sbin" after
zshrc_add_path "/bin" after
zshrc_add_path "/sbin" after
# Override macOS's outdated curl version. This has to be prefixed so it overrides the /usr/bin/curl path.
if type brew > /dev/null 2>&1; then
if [ -s "$(brew --prefix)/opt/curl/bin/curl" ]; then
zshrc_add_path "$(brew --prefix)/opt/curl/bin:${PATH}" before
fi
if [ -d "$(brew --prefix)/opt/make/libexec/gnubin" ]; then
zshrc_add_path "$(brew --prefix)/opt/make/libexec/gnubin:${PATH}" before
fi
if [ -d "$(brew --prefix)/opt/binutils/bin" ]; then
zshrc_add_path "$(brew --prefix)/opt/binutils/bin:${PATH}" before
LDFLAGS="-L$(brew --prefix)/opt/binutils/lib"
export LDFLAGS
CPPFLAGS="-I$(brew --prefix)/opt/binutils/include"
export CPPFLAGS
fi
if type gsed > /dev/null 2>&1; then
# Make the gsed application universal for this system!
if [ ! -e "${HOME}/.local/bin/sed" ]; then
mkdir -p "${HOME}/.local/bin"
ln -s "$(command -v gsed)" "${HOME}/.local/bin/sed"
echo "NOTE: GNU gsed is now linked to sed in ${HOME}/.local/bin; you are no longer using BSD sed!"
fi
fi
fi
zshrc_add_path "${HOME}/.local/bin" before
# Override system-installed Rust/Cargo.
if [ -s "$HOME/.cargo/env" ]; then
. "$HOME/.cargo/env"
fi
# Override system-installed packages with the Go variety.
zshrc_add_path "/usr/local/go/bin" before
if [ -n "$GOPATH" ]; then
zshrc_add_path "${GOPATH}/bin" before
fi
if [ -n "$GOROOT" ]; then
zshrc_add_path "${GOROOT}/bin" before
fi
# Dynamically add the ruby gem paths.
if type gem > /dev/null 2>&1; then
# Sometimes this path doesn't exist.
local user_gem_path=$(gem env user_gemdir 2>/dev/null)
if [ $? -eq 0 ]; then
zshrc_add_path "${user_gem_path}/bin" before
fi
local gem_path=$(gem env gemdir 2>/dev/null)
if [ $? -eq 0 ]; then
zshrc_add_path "${gem_path}/bin" before
fi
fi
zshrc_add_path "${HOME}/.config/yarn/global/node_modules/.bin" before
zshrc_add_path "${HOME}/.yarn/bin" before
# Miscellaneous paths
zshrc_add_path "${HOME}/.SpaceVim/bin" before
zshrc_add_path "${HOME}/.anaconda2/bin" before
zshrc_add_path "${HOME}/anaconda2/bin" before
zshrc_add_path "${HOME}/src/cquery/build/release/bin" before
zshrc_add_path "${HOME}/src/depot_tools" before
zshrc_add_path "${HOME}/.adb-fastboot/platform-tools" before
zshrc_add_path "${HOME}/bin/balena-cli" before
zshrc_add_path "${KREW_ROOT:-$HOME/.krew}/bin" before
if [ -n "${PYENV_ROOT}" ]; then
zshrc_add_path "${PYENV_ROOT}/bin" before
fi
# Always wins, these are mine.
zshrc_add_path "${HOME}/bin" before
}
zshrc_load_library() {
# Join a telnet based movie theater.
starwars() {
telnet towel.blinkenlights.nl
}
mirrorweb() {
wget --mirror --page-requisites --no-parent --adjust-extension --convert-links --recursive --level=inf --continue --no-clobber $@
}
# Download and run a curl based Party Parrot animation.
parrot() {
curl parrot.live
}
# Duplicate of parrot()
party() {
parrot
}
# Login and play/watch Nethack from anywhere.
nethack() {
telnet nethack.alt.org
}
weather() {
curl "wttr.in/$1?m"
}
# Aliases, functions, commands, etc.
# From https://github.com/xvoland/Extract/blob/master/extract.sh
# TODO: Add support for cpio, ar, iso
# TODO: Add progress bar, remove verbose flag
decompress() {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: inflate <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " inflate <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
return 1
else
for n in $@
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n"
;;
*.lzma)
unlzma ./"$n"
;;
*.bz2)
bunzip2 ./"$n"
;;
*.rar)
unrar x -ad ./"$n"
;;
*.gz)
gunzip ./"$n"
;;
*.zip)
unzip ./"$n"
;;
*.z)
uncompress ./"$n"
;;
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n"
;;
*.xz)
unxz ./"$n"
;;
*.exe)
cabextract ./"$n"
;;
*)
echo "inflate: '$n' - unknown archive method"
return 1
;;
esac
else