-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshrc
384 lines (350 loc) · 12 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
# shellcheck disable=all
# Default {{{1 #
ZPFX="$HOME/.local"
typeset -A ZINIT
ZINIT[MAN_DIR]="$ZPFX/share/man"
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
if [[ -f $XDG_DATA_HOME/zinit/plugins/zinit/zinit.zsh ]]; then
. $XDG_DATA_HOME/zinit/plugins/zinit/zinit.zsh
elif (($+commands[git])); then
git clone --depth=1 https://github.com/zdharma-continuum/zinit \
$XDG_DATA_HOME/zinit/plugins/zinit
. $XDG_DATA_HOME/zinit/plugins/zinit/zinit.zsh
else
return
fi
# some terminal emulators don't start $SHELL with -l,
# which will not source .zprofile
if ((! $+DOCKER_BUILDKIT)); then
. ~/.zprofile
fi
# brew add some paths which may contain tmux
zinit id-as'.brew' depth'1' \
atclone'/home/linuxbrew/.linuxbrew/bin/brew shellenv > brew.sh
zcompile *.sh' \
if'[ -x /home/linuxbrew/.linuxbrew/bin/brew ]' \
for zdharma-continuum/null
# tmux firstly avoid load ~/.zshrc twice
# exec tmux will met bug in android
# tmux on android and windows is slow because it cannot run in background
# don't run tmux on them
if [[ $OSTYPE == linux-gnu ]] && (($+commands[tmux])) \
&& (( ! ($+TMUX || $+SSH_TTY || $+HOMEBREW_DEBUG_INSTALL))); then
if [[ $KITTY_WINDOW_ID == 1 || $WEZTERM_PANE == 0 ]] || (($+ALACRITTY_WINDOW_ID)); then
exec tmux new -As0
elif [[ $TERM == linux ]]; then
tmux new -As0
fi
fi
typeset -F SECONDS
WORDCHARS=
READNULLCMD=bat
ZLE_RPROMPT_INDENT=0
HISTFILE=$HOME/.zsh_history
HISTSIZE=100000
SAVEHIST=$HISTSIZE
setopt nobanghist
setopt autopushd
setopt chaselinks
setopt pushdignoredups
# ubuntu 18.04
if (($+options[cdsilent])); then
setopt cdsilent
fi
setopt pushdsilent
setopt globstarshort
setopt magicequalsubst
setopt numericglobsort
setopt rematchpcre
setopt incappendhistory
setopt extendedhistory
setopt histignorespace
setopt histignorealldups
setopt histreduceblanks
setopt histverify
setopt noflowcontrol
setopt interactivecomments
setopt rcquotes
zmodload zsh/pcre
if (($+aliases[run-help])); then
unalias run-help
fi
autoload -Uz run-help
autoload -Uz zcalc
autoload -Uz zmv
autoload -Uz compinit && compinit
autoload -Uz zmathfunc && zmathfunc
bindkey -e
bindkey "\x1b[13;2u" accept-line
bindkey -Mvicmd "\x1b[13;2u" accept-line
bindkey "\x1b[13;5u" accept-line
bindkey -Mvicmd "\x1b[13;5u" accept-line
bindkey ^Xh _complete_help
autoload -U edit-command-line \
&& bindkey '^X^E' edit-command-line
bindkey ^U backward-kill-line
bindkey ^Q vi-quoted-insert
bindkey '^]' vi-find-next-char
bindkey '^[]' vi-find-prev-char
bindkey '^[W' copy-region-as-kill
bindkey '^[l' down-case-word
# vi
_complete_files () {
eval "$_comp_setup"
_main_complete _files
}
compdef -k _complete_files complete-word '^X^F'
bindkey '^[' vi-cmd-mode
bindkey '^[i' expand-or-complete-prefix
bindkey -Mvicmd cc vi-change-whole-line
autoload -Uz replace-string \
&& zle -N replace-regex replace-string \
&& bindkey '^^' replace-regex
autoload -Uz narrow-to-region \
&& zle -N narrow-to-region \
&& bindkey -Mvicmd ' ' narrow-to-region
autoload -Uz transpose-lines \
&& zle -N transpose-lines \
&& bindkey '^[T' transpose-lines
zstyle ':completion:*' list-separator ''
zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' \
'r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' muttrc \
${XDG_CONFIG_HOME:-$HOME/.config}/neomutt/neomuttrc
zstyle ':completion:*' mail-directory ${XDG_CACHE_HOME:-$HOME/.cache}/neomutt
zstyle ':completion:*' word true
zstyle ':completion::complete:*' use-cache true
zstyle ':completion::complete:*' call-command true
zstyle ':completion:*:processes' command "ps -wu$USER -opid,user,comm"
zstyle ':completion:*:git-checkout:*' sort false
zstyle ':completion:*:coredumpctl:*' sort false
zstyle ':completion:*' option-stacking true
# work when fzf-tab is not installed
zstyle ':completion:*' menu select
zstyle ':completion:*' extra-verbose true
alias mv='mv -i'
alias cp='cp -ri'
alias scp='scp -r'
alias rsync='rsync -avzP'
alias rm='rm -i'
alias mkdir='mkdir -p'
alias rmdir='rmdir -p'
alias rename='rename -i'
if (($+commands[perl-rename])); then
alias perl-rename='perl-rename -i'
fi
if (($+commands[bear])); then
alias make='bear -- make'
fi
if (($+commands[eza])); then
alias ls='eza --icons --git -h'
alias tree='eza --icons -T'
elif (($+commands[exa])); then
alias ls='exa --icons -h'
alias tree='exa --icons -T'
else
alias ls='ls --color=auto -h'
fi
if (( $+HOMEBREW_PREFIX )); then
fpath+=$HOMEBREW_PREFIX/share/zsh/site-functions
# https://github.com/msys2/MSYS2-packages/issues/2997
elif (( $+MSYSTEM_PREFIX )); then
fpath+=$MSYSTEM_PREFIX/share/zsh/site-functions
fi
# 1}}} Default #
# Plugin {{{1 #
zinit id-as depth'1' for zdharma-continuum/z-a-bin-gem-node
# 1}}} Plugin #
# StatusLine {{{1 #
# p10k cannot support any ice, see its README.md
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
. "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# https://bugs.archlinux.org/task/80028
if [[ -f /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme ]]; then
. /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme
elif [[ -f /run/current-system/sw/share/zsh-powerlevel10k/powerlevel10k.zsh-theme ]]; then
. /run/current-system/sw/share/zsh-powerlevel10k/powerlevel10k.zsh-theme
else
zinit id-as depth'1' for romkatv/powerlevel10k
fi
[[ ! -f ${XDG_CONFIG_HOME:-$HOME/.config}/p10k.zsh ]] || . ${XDG_CONFIG_HOME:-$HOME/.config}/p10k.zsh
# 1}}} StatusLine #
# Cursor {{{1 #
# add-surround in visual mode cannot be highlighted
MODE_CURSOR_VIINS='blinking bar'
MODE_CURSOR_REPLACE='blinking underline'
MODE_CURSOR_VICMD='blinking block'
MODE_CURSOR_SEARCH=underline
MODE_CURSOR_VISUAL=block
MODE_CURSOR_VLINE=bar
zinit id-as depth'1' wait lucid \
atload'vim_mode_set_keymap $(vim-mode-initial-keymap)
bindkey -Mvisual s add-surround
bindkey -e' \
for softmoth/zsh-vim-mode
# 1}}} Cursor #
# Hook {{{1 #
zinit id-as'.direnv' depth'1' wait lucid \
atclone'direnv hook zsh > direnv.sh
zcompile *.sh' \
if'(($+commands[direnv]))' \
for zdharma-continuum/null
zinit id-as'.pyenv' depth'1' wait lucid \
atclone'pyenv init - > pyenv.sh
zcompile *.sh' \
if'(($+commands[pyenv]))' \
for zdharma-continuum/null
# https://github.com/Kaggle/kaggle-api/issues/446
zinit id-as'.pass' depth'1' as'null' wait lucid \
atclone'echo "CODESTATS_API_KEY=$(pass ls codestats/$HOST)" > pass.sh
echo "export KAGGLE_USERNAME=$(pass ls kaggle/username)" >> pass.sh
echo "export KAGGLE_KEY=$(pass ls kaggle/key)" >> pass.sh
echo "export OPENAI_API_KEY=$(pass ls openai/api_key)" >> pass.sh
echo echo "$(pass ls wakatime/api_key)" > wakatime.sh
chmod +x wakatime.sh
pass ls codestats/$HOST > codestats.txt' \
if'(($+commands[pass]))' \
for zdharma-continuum/null
zinit id-as depth'1' for mdumitru/last-working-dir
zinit id-as depth'1' for lljbash/zsh-renew-tmux-env
zinit id-as depth'1' wait lucid for RobSis/zsh-reentry-hook
zinit id-as depth'1' wait lucid for Freed-Wu/zsh-command-not-found
# 1}}} Hook #
# Complete {{{1 #
zinit id-as'.vivid' depth'1' wait lucid \
atclone'echo "export LS_COLORS=\"$(vivid generate molokai)\"" > vivid.sh
zcompile *.sh' \
atload'zstyle ":completion:*" list-colors "${(s.:.)LS_COLORS}"' \
if'(($+commands[vivid]))' \
for zdharma-continuum/null
FZF_TMUX_HEIGHT=100%
zstyle ':fzf-tab:*' prefix ''
zstyle ':fzf-tab:*' single-group prefix color header
zstyle ':fzf-tab:*' continuous-trigger 'ctrl-_'
zstyle ':fzf-tab:*' switch-group 'alt-,' 'alt-.'
zinit id-as depth'1' wait lucid \
if'(($+commands[fzf]))' \
for Aloxaf/fzf-tab
zinit id-as depth'1' wait lucid \
if'(($+commands[fzf]))' \
for Freed-Wu/fzf-tab-source
zinit id-as depth'1' wait lucid for petronny/pinyin-completion
# 1}}} Complete #
# Log {{{1 #
# must before suggest, see its README.md
zinit id-as depth'1' wait lucid from'gitlab' \
if'(($+CODESTATS_API_KEY))' \
for code-stats/code-stats-zsh
ZSH_WAKATIME_PROJECT_DETECTION=true
zinit id-as depth'1' wait lucid \
if'(($+commands[wakatime]))' \
for wbingli/zsh-wakatime
# 1}}} Log #
# Syntax {{{1 #
zinit id-as depth'1' wait lucid for zdharma-continuum/fast-syntax-highlighting
# 1}}} Syntax #
# Suggest {{{1 #
# must load before zsh-autosuggestions
zinit id-as depth'1' wait lucid \
atload'bindkey "^[p" history-substring-search-up
bindkey "^[n" history-substring-search-down
bindkey -Mvicmd gk history-substring-search-up
bindkey -Mvicmd gj history-substring-search-down
bindkey -Mvicmd zk history-search-backward
bindkey -Mvicmd zj history-search-forward' \
for zsh-users/zsh-history-substring-search
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(end-of-line vi-end-of-line vi-add-eol)
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(vi-find-next-char
forward-char vi-forward-char forward-word emacs-forward-word
vi-forward-word vi-forward-word-end vi-forward-blank-word
vi-forward-blank-word-end vi-find-next-char vi-find-next-char-skip
)
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(yank yank-pop
history-search-forward history-search-backward
history-beginning-search-forward history-beginning-search-backward
history-substring-search-up history-substring-search-down
up-line-or-beginning-search down-line-or-beginning-search
up-line-or-history down-line-or-history accept-line copy-earlier-word
)
ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
orig-\*
beep
run-help
set-local-history
which-command
zle-\*
)
zinit id-as depth'1' wait lucid \
atload'_zsh_autosuggest_start
bindkey "^\\" autosuggest-toggle' \
for zsh-users/zsh-autosuggestions
# 1}}} Suggest #
# HotKey {{{1 #
# cursor cannot display correctly after start zsh, quit neovim, switch tmux
# tmux selectw will result in wrong cursor in insert mode
# and cannot work when bindkey -e
# zinit id-as depth'1' wait lucid \
# atload'bindkey -sMvisual s S
# bindkey -e' \
# for jeffreytse/zsh-vi-mode
zinit id-as depth'1' wait lucid \
atload'bindkey -Mvisual Q exchange
bindkey -Mvicmd Q exchange' \
for okapia/zsh-viexchange
zinit id-as depth'1' wait lucid for zsh-vi-more/vi-increment
# conflict with zsh-system-clipboard
# zinit id-as depth'1' wait lucid \
# atload'bindkey -Mvicmd " " vi-easy-motion' \
# for IngoHeimbach/zsh-easy-motion
ZSH_SYSTEM_CLIPBOARD_TMUX_SUPPORT=true
zinit id-as depth'1' wait lucid \
if'(($+commands[xsel] || $+commands[xclip] || $+commands[wl-copy]))' \
for kutsan/zsh-system-clipboard
zinit id-as depth'1' wait lucid \
atload'bindkey "^[/" redo
bindkey "^[y" yank-pop' \
for zdharma-continuum/zsh-editing-workbench
zinit id-as depth'1' wait lucid for zdharma-continuum/zui
# https://github.com/zdharma-continuum/zsh-cmd-architect/pull/1
zinit id-as depth'1' wait lucid for zdharma-continuum/zsh-cmd-architect
# https://github.com/joshskidmore/zsh-fzf-history-search/pull/20
ZSH_FZF_HISTORY_SEARCH_FZF_ARGS='+s +m -x -e --preview-window=hidden'
zinit id-as depth'1' wait lucid \
if'(($+commands[fzf]))' \
atload'bindkey -Mvicmd / fzf_history_seach' \
for joshskidmore/zsh-fzf-history-search
EMOJI_FZF_BINDKEY=^X^I
zinit id-as depth'1' wait lucid \
if'(($+commands[emoji-fzf] && $+commands[fzf]))' \
for pschmitt/emoji-fzf.zsh
# 1}}} HotKey #
# Insert {{{1 #
zinit id-as depth'1' wait lucid for MenkeTechnologies/zsh-expand
zinit id-as depth'1' wait lucid for hlissner/zsh-autopair
# 1}}} Insert #
# Colorize {{{1 #
zinit id-as depth'1' wait lucid for Freed-Wu/zsh-help
zinit id-as depth'1' wait lucid for Freed-Wu/zsh-colorize-functions
zinit id-as depth'1' wait lucid for zpm-zsh/colorize
zinit id-as depth'1' wait lucid \
if'(($+commands[mysql]))' \
for zpm-zsh/mysql-colorize
# 1}}} Colorize #
# Function {{{1 #
zinit id-as depth'1' wait lucid \
if'(($+commands[xdg-open] || $+commands[open]))' \
for sineto/web-search
# 1}}} Function #
# Compatible {{{1 #
zinit id-as depth'1' wait lucid for Freed-Wu/zsh-completions-for-cross-compilers
compdef _gnu_generic ffmpeg ffplay ffprobe file
# https://github.com/3v1n0/zsh-bash-completions-fallback/issues/6
compdef _python python
compdef _pydoc pydoc
compdef _pip pip
# after compinit
zinit id-as depth'1' wait lucid for 3v1n0/zsh-bash-completions-fallback
zinit id-as depth'1' null for zdharma-continuum/zinit
# 1}}} Compatible #
# ex: foldmethod=marker