This repository has been archived by the owner on Nov 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
526 lines (417 loc) · 17 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
#
# Exports
#
path+=( /sbin /usr/sbin )
#module_path+=("$HOME/.zinit/bin/zmodules/Src"); zmodload zdharma/zplugin &>/dev/null
typeset -g HISTSIZE=290000 SAVEHIST=290000 HISTFILE=~/.zhistory ABSD=${${(M)OSTYPE:#*(darwin|bsd)*}:+1}
typeset -ga mylogs
zflai-msg() { mylogs+=( "$1" ); }
zflai-assert() { mylogs+=( "$4"${${${1:#$2}:+FAIL}:-OK}": $3" ); }
(( ABSD )) && {
export LSCOLORS=dxfxcxdxbxegedabagacad CLICOLOR="1"
export ANDROID_ROOT=/opt/android
}
export EDITOR="vim" LESS="-iRFX" CVS_RSH="ssh"
umask 022
#
# Setopts
#
setopt interactive_comments hist_ignore_dups octal_zeroes no_prompt_cr
setopt no_hist_no_functions no_always_to_end append_history list_packed
setopt inc_append_history complete_in_word no_auto_menu auto_pushd
setopt pushd_ignore_dups no_glob_complete no_glob_dots c_bases
setopt numeric_glob_sort no_share_history promptsubst auto_cd
setopt rc_quotes extendedglob notify
#setopt IGNORE_EOF
#setopt NO_SHORT_LOOPS
#setopt PRINT_EXIT_VALUE
#setopt RM_STAR_WAIT
#
# Bindkeys
#
autoload up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey -v
[[ -n "$terminfo[kpp]" ]] && bindkey "$terminfo[kpp]" up-line-or-beginning-search # PAGE UP
[[ -n "$terminfo[knp]" ]] && bindkey "$terminfo[knp]" down-line-or-beginning-search # PAGE DOWN
[[ -n "$terminfo[khome]" ]] && bindkey "$terminfo[khome]" beginning-of-line # HOME
[[ -n "$terminfo[kend]" ]] && bindkey "$terminfo[kend]" end-of-line # END
[[ -n "$terminfo[kdch1]" ]] && bindkey "$terminfo[kdch1]" delete-char # DELETE
[[ -n "$terminfo[kbs]" ]] && bindkey "$terminfo[kbs]" backward-delete-char # BACKSPACE
zflai-assert "${+terminfo[kpp]}${+terminfo[knp]}${+terminfo[khome]}${+terminfo[kend]}" "1111" "terminfo test" "[zshrc] "
bindkey "^A" beginning-of-line "^E" end-of-line
bindkey "^?" backward-delete-char "^H" backward-delete-char
bindkey "^W" backward-kill-word "\e[1~" beginning-of-line
bindkey "\e[7~" beginning-of-line "\e[H" beginning-of-line
bindkey "\e[4~" end-of-line "\e[8~" end-of-line
bindkey "\e[F" end-of-line "\e[3~" delete-char
bindkey "^J" accept-line "^M" accept-line
bindkey "^T" accept-line "^R" history-incremental-search-backward
#
# Modules
#
zmodload -i zsh/complist
#
# Autoloads
#
unalias run-help
autoload -Uz allopt zed zmv zcalc colors run-help
colors
autoload -Uz edit-command-line
zle -N edit-command-line
#bindkey -M vicmd v edit-command-line
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
#url_quote_commands=(links wget youtube-dl curl); zstyle -e :urlglobber url-other-schema '[[ $url_quote_commands[(i)$words[1]] -le ${#url_quote_commands} ]] && reply=("*") || reply=(http https ftp ssh)'
#
# Aliases
#
alias pl='print -rl --'
alias pRl='print -l --'
#alias ls="gls -bh --color=auto"
alias ls="psls -bh --color=auto"
alias l="ls" l.='ls -d .*' la='ls -a' ll='ls -lbt created'
alias mv='mv -v' cp='cp -v' rm='command rm -i'
alias df='df -h' du='du -h' plast="last -20"
alias reload="exec $SHELL -l -i" grep="command grep --colour=auto --binary-files=without-match --directories=skip"
alias lynx="command lynx -accept-all-cookies"
alias ult="ulimit -c 195312; echo $$"
ulimit -c unlimited
# Git
alias g1log_branches="git log --color=always --oneline --decorate --graph --branches"
alias g1log_branches_intag="echo You can append a tag name; LANG=C sleep 0.5; git log --color=always --oneline --decorate --graph --branches"
alias g1log_simplify_decfull="git log --color=always --decorate=full --simplify-by-decoration"
alias g1log_simplify="git log --color=always --simplify-by-decoration --decorate"
# Image Magick
alias i1montage_concat_topbo_black="montage -mode concatenate -tile 1x -background black"
alias i1montage_concat_topbo_white="montage -mode concatenate -tile 1x -background white"
alias i1convert_append_topbo_black="convert -append -background black"
alias i1convert_append_topbo_white="convert -append -background white"
alias i1convert_append_lefri_black="convert +append -background black"
alias i1convert_append_lefri_white="convert +append -background white"
# Homebrew
alias b1s="brew search" b1i="brew install" b1muver="brew ls --versions --multiple"
alias b1info="brew info" b1desc="brew desc" b1descs="brew desc --search"
alias b1ls="brew list" b1leaves="brew leaves" b1upgrade="brew update; brew upgrade; brew cleanup"
alias b1home="brew home" b1u="brew uninstall" b1uses_installed="brew uses --installed"
alias b1up="brew upgrade"
# Homebrew/cask
alias b1cask_s="brew cask search" b1cask_i="brew cask install"
alias b1cask_u="brew cask uninstall" b1cask_info="brew cask info"
alias b1cask_ls="brew cask list" b1cask_home="brew cask home"
alias b1cask_up="brew cask upgrade"
# Quick typing
alias n1ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias n1ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
alias n1sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias n1httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
# Show/hide hidden files in Finder
alias x1show_hidden="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
alias x1hide_hidden="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"
# Hide/show all desktop icons (useful when presenting)
alias x1hide_desktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
alias x1show_desktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"
# Disable / enable Spotlight
alias x1spotoff="sudo mdutil -a -i off"
alias x1spoton="sudo mdutil -a -i on"
# Flush Directory Service cache
alias x1flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
alias x1mute="osascript -e 'set volume output muted true'"
alias x1lock="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
# Email screenshot
alias x1email_screen="screencapture -C -M screen-`date +%d.%m.%Y-%H`.png"
alias x1email_screen10s="screencapture -T 10 -C -M screen-`date +%d.%m.%Y-%H`.png"
alias x1email_window="screencapture -W -M screen-`date +%d.%m.%Y-%H`.png"
alias x1email_snippet="screencapture -s -M screen-`date +%d.%m.%Y-%H`.png"
#
# General tools
#
alias newest_ls="ls -lh --sort date -r --color=always | head -25"
alias cpfile="rsync --progress"
alias zmv='noglob zmv -w'
alias recently_changed='find . -newerct "15 minute ago" -print'
recently_changed_x() { find . -newerct "$1 minute ago" -print; }
alias -g SPRNG=" | curl -F 'sprunge=<-' http://sprunge.us"
#
# Patches for various problems
#
alias slocate='locate'
alias updatedb="sudo /usr/libexec/locate.updatedb"
# alias ls=psls ... - retain ls options but substitute the command with psls
if altxt=`alias ls`; then
altxt="${altxt#alias }" # for sh
if [ "$altxt" != "${altxt#ls=\'(ls|exa)}" ]; then
altxt=${altxt#ls=\'exa}
altxt=${altxt%\'}
altxt="ls=psls$altxt"
alias "$altxt"
zflai-msg "[zshrc] \`ls' alias: $altxt"
fi
else
alias ls="psls"
zflai-msg "[zshrc] \`ls' alias: ls=psls"
fi
unset altxt
fpath+=( $HOME/functions )
autoload -Uz psprobe_host psffconv pssetup_ssl_cert psrecompile pscopy_xauth \
psls pslist psfind \
mandelbrot optlbin_on optlbin_off localbin_on localbin_off g1all g1zip \
zman \
t1uncolor t1fromhex t1countdown \
f1rechg_x_min f1biggest \
n1gglinks n1dict n1diki n1gglinks n1ggw3m n1ling n1ssl_tunnel \
n1ssl_rtunnel \
pngimage deploy-code deploy-message \
exchange
autoload +X zman
functions[zzman]="${functions[zman]}"
function run_diso {
sh -c "$@" &
disown
}
function copydir {
pwd | tr -d "\r\n" | xsel -ib
}
function from-where {
echo $^fpath/$_comps[$1](N)
whence -v $_comps[$1]
#which $_comps[$1] 2>&1 | head
}
whichcomp() {
for 1; do
( print -raC 2 -- $^fpath/${_comps[$1]:?unknown command}(NP*$1*) )
done
}
osxnotify() {
osascript -e 'display notification "'"$*"'"'
}
localbin_on
#PS1="READY > "
zstyle ":plugin:zconvey" greeting "none"
zstyle ':notify:*' command-complete-timeout 3
zstyle ':notify:*' notifier plg-zsh-notify
palette() { local colors; for n in {000..255}; do colors+=("%F{$n}$n%f"); done; print -cP $colors; }
# Run redis-server port forwarding, from the public 3333 port
#n1ssl_rtunnel 3333 localhost 4815 zredis.pem zredis_client.crt &!
zflai-msg "[zshrc] ssl tunnel PID: $!"
#
# Zplugin
#
typeset -F4 SECONDS=0
[[ ! -f ~/.zinit/bin/zinit.zsh ]] && {
command mkdir -p ~/.zinit
command git clone https://github.com/zdharma/zinit ~/.zinit/bin
}
source "$HOME/.zinit/bin/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# Zplugin annexes
# zinit-zsh/z-a-man \
zinit light-mode for \
zinit-zsh/z-a-unscope \
zinit-zsh/z-a-as-monitor \
zinit-zsh/z-a-patch-dl \
zinit-zsh/z-a-submods \
zinit-zsh/z-a-rust \
zinit-zsh/z-a-bin-gem-node
# Fast-syntax-highlighting & autosuggestions
zinit wait lucid for \
atinit"ZINIT[COMPINIT_OPTS]=-C; zpcompinit; zpcdreplay" \
zdharma/fast-syntax-highlighting \
atload"!_zsh_autosuggest_start" \
zsh-users/zsh-autosuggestions \
blockf \
zsh-users/zsh-completions
# lib/git.zsh is loaded mostly to stay in touch with the plugin (for the users)
# and for the themes 2 & 3 (lambda-mod-zsh-theme & lambda-gitster)
zinit wait lucid for \
zdharma/zsh-unique-id \
svn silent PZTM::archive \
PZTM::directory \
PZTM::utility
# Theme no. 1 - zprompts
zinit lucid \
load'![[ $MYPROMPT = 1 ]]' \
unload'![[ $MYPROMPT != 1 ]]' \
atload'!promptinit; typeset -g PSSHORT=0; prompt sprint3 yellow red green blue' \
nocd for \
psprint/zprompts
# Theme no. 2 – lambda-mod-zsh-theme
zinit lucid load'![[ $MYPROMPT = 2 ]]' unload'![[ $MYPROMPT != 2 ]]' nocd for \
halfo/lambda-mod-zsh-theme
# Theme no. 3 – lambda-gitster
zinit lucid load'![[ $MYPROMPT = 3 ]]' unload'![[ $MYPROMPT != 3 ]]' nocd for \
ergenekonyigit/lambda-gitster
# Theme no. 4 – geometry
zinit lucid load'![[ $MYPROMPT = 4 ]]' unload'![[ $MYPROMPT != 4 ]]' \
atload'!geometry::prompt' nocd \
atinit'GEOMETRY_COLOR_DIR=63 GEOMETRY_PATH_COLOR=63' for \
geometry-zsh/geometry
# Theme no. 5 – pure
zinit lucid load'![[ $MYPROMPT = 5 ]]' unload'![[ $MYPROMPT != 5 ]]' \
pick"/dev/null" multisrc"{async,pure}.zsh" atload'!prompt_pure_precmd' nocd for \
sindresorhus/pure
# Theme no. 6 - agkozak-zsh-theme
zinit lucid load'![[ $MYPROMPT = 6 ]]' unload'![[ $MYPROMPT != 6 ]]' \
atload'!_agkozak_precmd' nocd atinit'AGKOZAK_FORCE_ASYNC_METHOD=subst-async' for \
agkozak/agkozak-zsh-theme
# Theme no. 7 - zinc
zinit load'![[ $MYPROMPT = 7 ]]' unload'![[ $MYPROMPT != 7 ]]' \
compile"{zinc_functions/*,segments/*,zinc.zsh}" nocompletions \
atload'!prompt_zinc_setup; prompt_zinc_precmd' nocd for \
robobenklein/zinc
# Theme no. 8 - git-prompt
zinit lucid load'![[ $MYPROMPT = 8 ]]' unload'![[ $MYPROMPT != 8 ]]' \
atload'!_zsh_git_prompt_precmd_hook' nocd for \
woefe/git-prompt.zsh
# zunit, color
zinit wait"2" lucid as"null" for \
sbin atclone"./build.zsh" atpull"%atclone" \
molovo/zunit \
sbin"color.zsh -> color" \
molovo/color
# revolver
zinit wait"2" lucid as"program" pick"revolver" for psprint/revolver
# zpm-zsh/material-dircolors
zinit pack for dircolors-material
# pyenv
zinit pack=bgn for pyenv
# Zconvey shell integration plugin
zinit wait lucid \
sbin"cmds/zc-bg-notify" sbin"cmds/plg-zsh-notify" for \
zdharma/zconvey
# zsh-startify, a vim-startify like plugin
: zinit wait"0b" lucid atload"zsh-startify" for zdharma/zsh-startify
: zinit wait lucid pick"manydots-magic" compile"manydots-magic" for knu/zsh-manydots-magic
# remark
zinit pack for remark
# zsh-autopair
# fzf-marks, at slot 0, for quick Ctrl-G accessibility
zinit wait lucid for \
hlissner/zsh-autopair \
urbainvaes/fzf-marks
# A few wait"1 plugins
zinit wait"1" lucid for \
psprint/zsh-navigation-tools \
atinit'zstyle ":history-search-multi-word" page-size "7"' \
zdharma/history-search-multi-word \
atinit"local zew_word_style=whitespace" \
atload"select-word-style normal" \
psprint/zsh-editing-workbench
# Github-Issue-Tracker – the notifier thread
zinit pack for @github-issues
# Github-Issue-Tracker – the issue-puller thread
GIT_SLEEP_TIME=700
GIT_PROJECTS=zdharma/zsh-github-issues:zdharma/zinit:zdharma/fast-syntax-highlighting
zinit pack for @github-issues-srv
# Gitignore plugin – commands gii and gi
zinit wait"2" lucid trigger-load'!gi;!gii' \
dl'https://gist.githubusercontent.com/psprint/1f4d0a3cb89d68d3256615f247e2aac9/raw -> templates/Zsh.gitignore' \
for \
voronkovich/gitignore.plugin.zsh
# F-Sy-H automatic themes – available for patrons
# https://patreon.com/psprint
: zinit wait"1" lucid from"psprint@gitlab.com" for psprint/fsh-auto-themes
# ogham/exa, sharkdp/fd, fzf
zinit wait"2" lucid as"null" from"gh-r" for \
mv"fd* -> fd" sbin"fd/fd" fd
# A little more complex rustup configuration that uses Bin-Gem-Node annex
# and installs the cargo completion provided with rustup, using for-syntax
zinit id-as=rust as=null sbin="bin/*" lucid rustup \
atload="[[ ! -f ${ZINIT[COMPLETIONS_DIR]}/_cargo ]] && zi creinstall rust; \
export CARGO_HOME=\$PWD RUSTUP_HOME=\$PWD/rustup" for \
zdharma/null
zinit id-as=exa as=null cargo='!exa' for zdharma/null
# fzf, fzy
zinit wait pack"bgn-binary" for fzf
zinit wait pack"bgn" git for fzy
#zinit wait lucid debug for env
#zinit ice as'null'
#zinit snippet https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/darwin/amd64/kubectl
# A few wait'2' plugins
zinit wait"2" lucid for \
zdharma/declare-zsh \
zdharma/zflai \
blockf \
zdharma/zui \
zinit-zsh/zinit-console \
trigger-load'!crasis' \
zdharma/zinit-crasis \
atinit"forgit_ignore='fgi'" \
wfxr/forgit
# git-cal
zinit wait"2" lucid as"null" \
atclone'perl Makefile.PL PREFIX=$ZPFX' \
atpull'%atclone' make sbin"git-cal" for \
k4rthik/git-cal
# A few wait'3' git extensions
zinit as"null" wait"3" lucid for \
sbin Fakerr/git-recall \
sbin paulirish/git-open \
sbin paulirish/git-recent \
sbin davidosomething/git-my \
sbin atload"export _MENU_THEME=legacy" \
arzzen/git-quick-stats \
sbin iwata/git-now \
make"PREFIX=$ZPFX" tj/git-extras \
sbin"bin/git-dsf;bin/diff-so-fancy" zdharma/zsh-diff-so-fancy \
sbin"git-url;git-guclone" make"GITURL_NO_CGITURL=1" zdharma/git-url \
make"prefix=$ZPFX install" jonas/tig
# fbterm
: zinit wait"3" lucid as"command" \
pick"$ZPFX/bin/fbterm" \
dl"https://bugs.archlinux.org/task/46860?getfile=13513 -> ins.patch" \
dl"https://aur.archlinux.org/cgit/aur.git/plain/0001-Fix-build-with-gcc-6.patch?h=fbterm-git" \
patch"ins.patch; 0001-Fix-build-with-gcc-6.patch" \
atclone"./configure --prefix=$ZPFX" \
atpull"%atclone" \
make"install" reset for \
izmntuk/fbterm
# asciinema
: zinit wait lucid as"command" \
atinit"export PYTHONPATH=$ZPFX/lib/python3.7/site-packages/" \
atclone"PYTHONPATH=$ZPFX/lib/python3.7/site-packages/ \
python3 setup.py --quiet install --prefix $ZPFX" \
atpull'%atclone' test'0' \
pick"$ZPFX/bin/asciinema" for \
asciinema/asciinema
# Notifications, configured to use zconvey
: zinit wait lucid for marzocchi/zsh-notify
zflai-msg "[zshrc] Zplugin block took ${(M)$(( SECONDS * 1000 ))#*.?} ms"
MYPROMPT=1
#
# Zstyles & other
#
zle -N znt-kill-widget
bindkey "^Y" znt-kill-widget
cdpath=( "$HOME" "$HOME/github" "$HOME/github2" "$HOME/gitlab" ~/pkgs )
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
zstyle ":completion:*:descriptions" format "%B%d%b"
zstyle ':completion:*:*:*:default' menu yes select search
#zstyle ":completion:*" list-colors “${(s.:.)LS_COLORS}”
function double-accept { deploy-code "BUFFER[-1]=''"; }
zle -N double-accept
bindkey -M menuselect '^F' history-incremental-search-forward
bindkey -M menuselect '^R' history-incremental-search-backward
bindkey -M menuselect ' ' .accept-line
function mem() { ps -axv | grep $$ }
# added by travis gem
[ -f /Users/sgniazdowski/.travis/travis.sh ] && source /Users/sgniazdowski/.travis/travis.sh
export GOPATH="/Users/sgniazdowski/go"
# Ubuntu aliases
alias i='sudo apt-get install'
alias s='apt-cache search'
alias r='sudo apt-get remove'
# Some other stuff…
zinit-palette() {
for k ( "${(@kon)ZINIT[(I)col-*]}" ); do
local i=$ZINIT[$k]
print "$reset_color${(r:14:: :):-$k:} $i###########"
done
}
# sudo touch /etc/NetworkManager/conf.d/10-globally-managed-devices.conf
##[keyfile]
##unmanaged-devices=*,except:type:wifi,except:type:wwan,except:type:ethernet
zflai-msg "[zshrc] Finishing, loaded custom modules: ${(j:, :@)${(k)modules[@]}:#zsh/*}"