-
Notifications
You must be signed in to change notification settings - Fork 3
/
.zshrc
executable file
·555 lines (507 loc) · 16.5 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
export LANG="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
# fpath {{{
export ZSH=$HOME/.zsh
fpath=($ZSH $fpath)
fpath=(/opt/homebrew/share/zsh-completions $fpath)
# }}}
# {{{ modules
zmodload zsh/datetime
zmodload zsh/mathfunc
zmodload -i zsh/complist
zmodload -F zsh/parameter
zmodload zsh/termcap
zmodload zsh/terminfo
zmodload zsh/net/socket
zmodload zsh/net/tcp
zmodload zsh/system
zmodload zsh/attr
zmodload zsh/pcre
zmodload zsh/regex
# }}}
# autoload {{{
autoload add-zsh-hook
autoload -U colors && colors # Enables colours
autoload -U compinit && compinit -u -d "$ZSH/cache/zcompdump-$HOST"
autoload -U url-quote-magic
autoload allopt
autoload -U zcalc
autoload -Uz zmv
# }}}
# settings {{{
# general
setopt NO_BEEP
export KEYTIMEOUT=0
setopt AUTO_CD
setopt AUTO_PUSHD
setopt CDABLE_VARS
setopt IGNORE_EOF
setopt INTERACTIVE_COMMENTS
setopt PROMPT_SUBST
setopt TRANSIENT_RPROMPT
setopt RM_STAR_SILENT
setopt C_BASES
unsetopt FLOW_CONTROL
unsetopt flowcontrol
setopt PRINT_EIGHT_BIT
setopt NO_CORRECT
setopt NO_CORRECT_ALL
setopt EXTENDED_GLOB
setopt CLOBBER
# completion
unsetopt MENU_COMPLETE # do not autoselect the first completion entry
setopt AUTO_MENU # show completion menu on succesive tab press
setopt COMPLETE_IN_WORD
setopt ALWAYS_TO_END
setopt NOMATCH
setopt COMPLETE_IN_WORD
setopt LIST_PACKED
setopt LIST_TYPES # Show types in completion
setopt REC_EXACT # Recognize exact, ambiguous matches
setopt AUTO_NAME_DIRS
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_SILENT
setopt PUSHD_TO_HOME
WORDCHARS='*?[]~&;!$%^<>'
WORDCHARS=${WORDCHARS//[&=\/;\!#?[]~&;!$%^<>%\{]}
# history settings {{{
HISTFILE=$HOME/.history/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS # ignore duplication command history list
setopt SHARE_HISTORY # share command history data
setopt HIST_VERIFY
setopt INC_APPEND_HISTORY
setopt EXTENDED_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_SPACE
setopt APPEND_HISTORY
setopt LONG_LIST_JOBS
setopt -o sharehistory
# }}}
# }}}
# {{{ completions
if [[ "$OSTYPE" = darwin* ]]; then
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' users $USER
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
zstyle ':completion:*:*:*:*:processes*' force-list always
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:kill:*:processes' sort false
zstyle ':completion:*:*:kill:*:processes' command 'ps -u "$USER"'
zstyle ':completion:*:*:killall:*:processes' command 'ps --forest -A -o pid,user,cmd'
zstyle ':completion:*:processes-names' command "ps axho cmd= | sed 's:\([^ ]*\).*:\1:;s:\(/[^ ]*/\)::;/^\[/d'"
zstyle ':completion:*:processes' command 'ps -au$USER -o pid,time,cmd|grep -v "ps -au$USER -o pid,time,cmd"'
zstyle ':completion:*:matches' group yes
zstyle ':completion:*:options' description yes
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:descriptions' format $'\e[01;33m-- %d --\e[0m'
zstyle ':completion:*:messages' format $'\e[01;35m-- %d --\e[0m'
zstyle ':completion:*:warnings' format $'\e[01;31m-- no matches found --\e[0m'
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.*' insert-sections true
zstyle ':completion:*:man:*' menu yes select
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:cp:*' ignore-line yes
zstyle ':completion:*:mv:*' ignore-line yes
fi
compdef _gnu_generic slrnpull make df du mv cp makepkg
# disable named-directories autocompletion
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
cdpath=(.)
# zstyle ':completion:*:hosts' hosts $hosts
# Use caching so that commands like apt and dpkg complete are useable
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ${HOME}/.zsh/cache/
# Don't complete uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
mailman mailnull mldonkey mysql nagios \
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
operator pcap postfix postgres privoxy pulse pvm quagga radvd \
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
# ... unless we really want to.
zstyle '*' single-ignored show
# Force file name completion on C-x TAB, Shift-TAB.
zle -C complete-files complete-word _generic
zstyle ':completion:complete-files:*' completer _files
zstyle ':completion:complete-first:*' menu yes
zstyle -e :urlglobber url-other-schema '[[ $words[1] == scp ]] && reply=("*") || reply=(http https ftp)'
# }}}
# hooks {{{
function preexec {
emulate -L zsh
local -a cmd; cmd=(${(z)1})
}
# }}}
# key bindings {{{
eval "insert-cycledleft () { zle push-line; LBUFFER='pushd -q +1'; zle accept-line }"
zle -N insert-cycledleft
bindkey "\e[1;6D" insert-cycledleft
eval "insert-cycledright () { zle push-line; LBUFFER='pushd -q -0'; zle accept-line }"
zle -N insert-cycledright
bindkey "\e[1;6C" insert-cycledright
function _backward_kill_default_word() {
WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>' zle backward-kill-word
}
zle -N backward-kill-default-word _backward_kill_default_word
bindkey '\e=' backward-kill-default-word # = is next to backspace
bindkey "^[[Z" complete-files
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^x^e' edit-command-line
_completeme() {
zle -I
TMPFILE=`mktemp 2> /dev/null || mktemp -t completeme 2> /dev/null`
completeme $TMPFILE
test -e $TMPFILE
source $TMPFILE
rm -f $TMPFILE
}
zle -N _completeme
function insert-selecta-path-in-command-line() {
local selected_path
# Print a newline or we'll clobber the old prompt.
echo
# Find the path; abort if the user doesn't select anything.
selected_path=$(find * -type f | fzy) || return
# Append the selection to the current command buffer.
eval 'LBUFFER="$LBUFFER$selected_path"'
# Redraw the prompt since Selecta has drawn several new lines of text.
zle reset-prompt
}
# Create the zle widget
zle -N insert-selecta-path-in-command-line
# Bind the key to the newly created widget
bindkey -r "^T"
bindkey "^T" "insert-selecta-path-in-command-line"
autoload -Uz narrow-to-region
# http://qiita.com/uchiko/items/f6b1528d7362c9310da0
function _selecta-select-history() {
local selected_entry
# Print a newline or we'll clobber the old prompt.
echo
# Find the path; abort if the user doesn't select anything.
BUFFER=$( fc -lnr 1 | fzy ) || return
# BUFFER=$( fc -lnr 1 | select -x ) || return
CURSOR=$#BUFFER
# Append the selection to the current command buffer.
# eval 'LBUFFER="$LBUFFER$selected_entry"'
# Redraw the prompt since Selecta has drawn several new lines of text.
zle reset-prompt
}
zle -N _selecta-select-history
bindkey -r "^R"
bindkey "^R" _selecta-select-history
function _hs-select-instance() {
local selected_instance
echo
selected_instance=$(aws --no-paginate --output json ec2 describe-instances --max-results 9999 --region eu-west-1 --query 'Reservations[*].Instances[*]' --filters 'Name=instance-state-code,Values=16' | ec2_instances_dump | sort | hs --filter-only) || return
selected_instance=$(echo $selected_instance | gawk '{print gensub(/^.*=(.*)/, "\\1", "g", $NF);}')
eval 'LBUFFER="$LBUFFER$selected_instance"'
zle reset-prompt
}
zle -N _hs-select-instance
bindkey '^q' _hs-select-instance
bindkey -e
bindkey '\ew' kill-region
bindkey -M isearch "^r" history-incremental-pattern-search-backward
#bindkey "^s" history-incremental-pattern-search-forward
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history
# make search up and down work, so partially type and hit up/down to find relevant stuff
bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search
bindkey "^[[7~" beginning-of-line # Home
bindkey "^[[8~" end-of-line # End
bindkey "^[[H" beginning-of-line
bindkey "^[[1~" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^[[4~" end-of-line
bindkey ' ' magic-space # also do history expansion on space
bindkey "\e[1;3D" backward-word
bindkey "\e3D" backward-word
bindkey '^[5D' backward-word
bindkey '^[[5D' backward-word
bindkey "\e[1;3C" forward-word
bindkey "\e3C" forward-word
bindkey '^[5C' forward-word
bindkey '^[[5C' forward-word
bindkey '^[[3~' delete-char
_physical_up_line() { zle backward-char -n $COLUMNS }
_physical_down_line() { zle forward-char -n $COLUMNS }
zle -N physical-up-line _physical_up_line
zle -N physical-down-line _physical_down_line
bindkey "\e\e[A" physical-up-line
bindkey "\e\e[B" physical-down-line
foreground-vi() {
fg %vi
}
zle -N foreground-vi
bindkey '^Z' foreground-vi
# file rename magick
bindkey "^[m" copy-prev-shell-word
zle -N self-insert url-quote-magic
# }}}
# functions {{{
function autoenv_chpwd_hook() {
local env_file="$PWD/.env"
local unenv_file="${dirstack[1]}/.unenv"
if [[ -f $unenv_file ]]; then
source $unenv_file
fi
if [[ -f $env_file ]]; then
source $env_file
return 0
fi
}
add-zsh-hook chpwd autoenv_chpwd_hook
# }}}
# prompt settings {{{
prompt_pure_preprompt_render() {
setopt localoptions noshwordsplit
local git_color=242
local -a preprompt_parts
preprompt_parts+=('%F{blue}%~%f')
typeset -gA prompt_pure_vcs_info
if [[ -n $prompt_pure_vcs_info[branch] ]]; then
preprompt_parts+=("%F{$git_color}"'${prompt_pure_vcs_info[branch]}%f')
fi
[[ -n $prompt_pure_username ]] && preprompt_parts+=('$prompt_pure_username')
local cleaned_ps1=$PROMPT
local -H MATCH
if [[ $PROMPT = *$prompt_newline* ]]; then
cleaned_ps1=${PROMPT%%${prompt_newline}*}${PROMPT##*${prompt_newline}}
fi
local -ah ps1
ps1=(
$prompt_newline
${(j. .)preprompt_parts}
$prompt_newline
$cleaned_ps1
)
PROMPT="${(j..)ps1}" #"
local expanded_prompt
expanded_prompt="${(S%%)PROMPT}" #"
if [[ $1 != precmd ]] && [[ $prompt_pure_last_prompt != $expanded_prompt ]]; then
zle && zle .reset-prompt
fi
typeset -g prompt_pure_last_prompt=$expanded_prompt
}
prompt_pure_precmd() {
prompt_pure_async_tasks
psvar[12]=
[[ -n $VIRTUAL_ENV ]] && psvar[12]="${VIRTUAL_ENV:t}"
prompt_pure_preprompt_render "precmd"
}
prompt_pure_async_vcs_info() {
setopt localoptions noshwordsplit
builtin cd -q $1 2>/dev/null
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' use-simple true
zstyle ':vcs_info:git*:*' get-revision true
zstyle ':vcs_info:*' max-exports 2
zstyle ':vcs_info:git*' formats '%b %6.6i' '%R'
zstyle ':vcs_info:git*' actionformats '%b %6.6i|%a' '%R'
vcs_info
local -A info
info[top]=$vcs_info_msg_1_
info[branch]=$vcs_info_msg_0_
print -r - ${(@kvq)info}
}
prompt_pure_async_tasks() {
setopt localoptions noshwordsplit
((!${prompt_pure_async_init:-0})) && {
async_start_worker "prompt_pure" -u -n
async_register_callback "prompt_pure" prompt_pure_async_callback
typeset -g prompt_pure_async_init=1
}
typeset -gA prompt_pure_vcs_info
local -H MATCH
if ! [[ $PWD = ${prompt_pure_vcs_info[pwd]}* ]]; then
async_flush_jobs "prompt_pure"
prompt_pure_vcs_info[branch]=
prompt_pure_vcs_info[top]=
fi
unset MATCH
async_job "prompt_pure" prompt_pure_async_vcs_info $PWD
[[ -n $prompt_pure_vcs_info[top] ]] || return
}
prompt_pure_async_callback() {
setopt localoptions noshwordsplit
local job=$1 code=$2 output=$3 exec_time=$4
case $job in
prompt_pure_async_vcs_info)
local -A info
typeset -gA prompt_pure_vcs_info
info=("${(Q@)${(z)output}}") #"
local -H MATCH
if [[ $info[top] = $prompt_pure_vcs_info[top] ]]; then
if [[ $prompt_pure_vcs_info[pwd] = ${PWD}* ]]; then
prompt_pure_vcs_info[pwd]=$PWD
fi
else
prompt_pure_vcs_info[pwd]=$PWD
fi
unset MATCH
prompt_pure_vcs_info[branch]=$info[branch]
prompt_pure_vcs_info[top]=$info[top]
prompt_pure_preprompt_render
;;
esac
}
prompt_pure_setup() {
export PROMPT_EOL_MARK=''
export VIRTUAL_ENV_DISABLE_PROMPT=1
prompt_opts=(subst percent)
setopt noprompt{bang,cr,percent,subst} "prompt${^prompt_opts[@]}" #"
if [[ -z $prompt_newline ]]; then
typeset -g prompt_newline=$'\n%{\r%}'
fi
zmodload zsh/datetime
zmodload zsh/zle
zmodload zsh/parameter
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
autoload -Uz async && async
add-zsh-hook precmd prompt_pure_precmd
PROMPT='%(12V.%F{242}%12v%f .)'
PROMPT='%(?.%F{magenta}.%F{red})❯%f '
}
prompt_pure_setup "$@"
source $ZSH/golang.plugin.zsh
source $ZSH/url-tools.plugin.zsh
source $ZSH/autoenv.plugin.zsh
[[ -x "$(command -v kubectl)" ]] && source <(kubectl completion zsh)
[[ -x "$(command -v jira)" ]] && eval "$(jira --completion-script-zsh)"
function iplot {
cat <<EOF | gnuplot
set terminal pngcairo enhanced font 'Fira Sans,10'
set autoscale
set samples 1000
set output '|kitty +kitten icat --stdin yes'
set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#fdf6e3" behind
plot $@
set output '/dev/null'
EOF
}
# }}}
# program settings & paths {{{
case $OSTYPE in
darwin*)
export OS=darwin
;;
linux*)
export OS=linux
;;
msys*)
export OS=windows
esac
export EDITOR=nvim
export GIT_EDITOR=nvim
export VISUAL=nvim
export CLICOLOR=1
export SSH_AUTH_SOCK=$HOME/.ssh/.ssh-agent.sock
export LESS="-rX"
export PAGER=less
export INPUTRC=${HOME}/.inputrc
export GOPATH=$HOME/.gocode
export GOBIN=$HOME/.gocode/bin
export GO111MODULE=on
export SOLARGRAPH_CACHE=$HOME/.cache/solargraph
export RUSTUP_HOME=$HOME/.cache/rustup
export RUST_SRC_PATH=${RUSTUP_HOME}/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust
export CARGO_HOME=$HOME/.cache/cargo
export FNM_DIR=$HOME/.cache/fnm
export npm_config_devdir=$HOME/.cache/node-gyp
export BUNDLE_USER_HOME=$HOME/.cache/bundle
export FRUM_DIR=$HOME/.cache/frum
export XDG_CONFIG_HOME=$HOME/.config/
export XDG_CACHE_HOME=$HOME/.cache/
export XDG_DATA_HOME=$HOME/.local/share/
export JAVA_HOME=/opt/homebrew/opt/openjdk@11/
export CONDA_PREFIX=$HOME/.conda
export HOMEBREW_CASK_OPTS="--appdir=${HOME}/Applications"
export HOMEBREW_NO_INSTALL_FROM_API=1
export HOMEBREW_NO_ENV_HINTS=1
if [[ $(arch) == "arm64" ]]; then
eval $(/opt/homebrew/bin/brew shellenv)
else
eval $(/usr/local/bin/brew shellenv)
fi
export ZVM_PATH=$XDG_DATA_HOME/zvm
export ZVM_INSTALL="$ZVM_PATH/self"
export PATH=\
/opt/blink/bin:\
/opt/cosmo/bin:\
/opt/homebrew/opt/bison/bin:\
$HOME/bin:\
$HOME/bin/$OS:\
$HOME/.krew/bin:\
$HOME/.local/bin:\
$HOME/.cache/cargo/bin:\
$ZVM_INSTALL:\
$ZVM_PATH/bin:\
$GOPATH/bin:\
$HOME/work/tools/jai/bin:\
/opt/homebrew/share/dotnet:\
/opt/homebrew/bin:\
/opt/homebrew/sbin:\
/usr/local/bin:\
/opt/local/sbin:\
$HOME/.platformio/penv/bin:\
$HOME/.dotnet/tools:\
/opt/X11/bin:\
/opt/homebrew/share/dotnet:\
/usr/bin:/bin:\
/usr/sbin:\
/sbin:\
$PATH
source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh
[[ -s "$HOME/.secrets/.zshrc_secret" ]] && . "$HOME/.secrets/.zshrc_secret"
alias tmux='tmux -2'
alias history='fc -l 1'
alias k="kubectl"
alias 4ed="${HOME}/Applications/Development\ Tools/4coder/4ed &"
[[ "$TERM" == "xterm-kitty" ]] && {
alias icat="kitty +kitten icat"
alias hg="kitty +kitten hyperlinked_grep"
}
if [[ "$OSTYPE" = msys* ]]; then
export PYTHONHOME=/c/tools/msys64/mingw64
export PATH=$PATH:/c/tools/neovim-msys/bin:/mingw64/bin:/usr/bin
fi
# if [[ $OSTYPE = linux* ]]; then
# export JAVA_HOME=/home/linuxbrew/.linuxbrew/opt/openjdk/libexec/
# export GOPATH=$HOME/.golinux
# export CARGO_HOME=$HOME/.cargo-linux
# export RUSTUP_HOME=$HOME/.rustup-linux
# export PATH=$PATH:/home/linuxbrew/.linuxbrew/bin
# fi
#
conda() {
__conda_setup="$('/opt/homebrew/Caskroom/miniconda/base/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/homebrew/Caskroom/miniconda/base/etc/profile.d/conda.sh" ]; then
. "/opt/homebrew/Caskroom/miniconda/base/etc/profile.d/conda.sh"
else
export PATH="/opt/homebrew/Caskroom/miniconda/base/bin:$PATH"
fi
fi
unset __conda_setup
}
export PIP_BREAK_SYSTEM_PACKAGES=1
export VCPKG_ROOT="$HOME/.cache/vcpkg"