-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zshrc
400 lines (315 loc) · 9.71 KB
/
dot_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
# vim:ft=zsh
source ~/.zsh/zsh-defer.zsh
fpath=(~/.zsh/completions $fpath)
export TERM=xterm-256color
export COLORTERM=truecolor
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
autoload -U colors && colors
[ -f ~/.config/zsh.env.zsh ] && source ~/.config/zsh.env.zsh
source ~/.config/zsh/prompt/colors.zsh
vim_ins_mode="%F{black}%K{yellow} INS %k%f"
vim_cmd_mode="%F{white}%K{red} NRM %k%f"
vim_vis_mode="%F{black}%K{blue} VIS %k%f"
vim_visline_mode="%F{black}%K{blue} VIL %k%f"
vim_rep_mode="%F{black}%K{green} REP %k%f"
vim_mode=$vim_ins_mode
function TRAPINT() {
vim_mode=$vim_ins_mode
return $(( 128 + $1 ))
}
function zvm_after_select_vi_mode() {
case $ZVM_MODE in
$ZVM_MODE_NORMAL)
vim_mode=$vim_cmd_mode
;;
$ZVM_MODE_INSERT)
vim_mode=$vim_ins_mode
;;
$ZVM_MODE_VISUAL)
vim_mode=$vim_vis_mode
;;
$ZVM_MODE_VISUAL_LINE)
vim_mode=$vim_visline_mode
;;
$ZVM_MODE_REPLACE)
vim_mode=$vim_rep_mode
;;
esac
}
autoload -Uz vcs_info add-zsh-hook
zstyle ':vcs_info:*' enable git hg
zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats '%F{4}%s%F{5}%F{3} @ %F{2}%b%f'
zstyle ':vcs_info:hg*:*' use-simple true
add-zsh-hook precmd vcs_info
zsh-defer -c 'RPROMPT="\${vcs_info_msg_0_} \${vim_mode}"'
bindkey -v
zmodload zsh/complist
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'l' vi-forward-char
# Enter interactive search
bindkey -M menuselect '^xi' vi-insert
export CLICOLOR=1
export LS_COLORS=$(cat ~/.lscolors)
export LESS_TERMCAP_mb=$'\e[1;31m'
export LESS_TERMCAP_md=$'\e[38;2;47;111;159;48;2;244;250;255m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[38;2;215;23;7m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;32m'
export GROFF_NO_SGR=1
# Options
setopt monitor
setopt auto_cd
setopt cdablevars
setopt pushd_ignore_dups
setopt interactive_comments
setopt append_history
setopt inc_append_history
setopt hist_ignore_dups
setopt hist_find_no_dups
setopt hist_reduce_blanks
setopt extended_history
setopt hist_expire_dups_first
setopt hist_verify
setopt share_history
setopt transient_rprompt
setopt prompt_subst
setopt multios
setopt correct_all
setopt autopushd
setopt pushdminus
setopt pushdsilent
setopt nobeep
setopt notify
REPORTTIME=5
zle_highlight=('paste:none')
HISTSIZE=3000
SAVEHIST=3000
# Completion
setopt complete_in_word
setopt always_to_end
setopt auto_menu
setopt auto_param_slash
# Enable completers
zstyle ':completion:*' completer _complete _approximate
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache"
# file list info
zstyle ':completion:*' file-list list
# activate color-completion
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# format on completion
zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
# insert all expansions for expand completer
zstyle ':completion:*:expand:*' tag-order all-expansions
zstyle ':completion:*:history-words' list false
# activate menu
zstyle ':completion:*:history-words' menu yes
# ignore duplicate entries
zstyle ':completion:*:history-words' remove-all-dups yes
zstyle ':completion:*:history-words' stop yes
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*' group-name ''
if [[ "$NOMENU" -eq 0 ]] ; then
# if there are more than 5 options allow selecting from a menu
zstyle ':completion:*' menu select=5
else
# don't use any menus at all
setopt no_auto_menu
fi
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:options' auto-description '%d'
# describe options in full
zstyle ':completion:*:options' description 'yes'
# complete manual by their section
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.*' insert-sections true
zstyle ':completion:*:man:*' menu yes select
# Search path for sudo completion
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
/usr/local/bin \
/usr/sbin \
/usr/bin \
/sbin \
/bin \
/usr/X11R6/bin
# provide .. as a completion
zstyle ':completion:*' specal-dirs ..
# case insensitive path-completion
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
# nvim completion
zstyle ':completion:*:*:nvim:*' ignored-patterns '*.(o|hex|elf|pyc|pdf|dup)'
zstyle ':completion:*:*:nvim:*' file-sort modification
# hx completion
zstyle ':completion:*:*:hx:*' ignored-patterns '*.(o|hex|elf|pyc|pdf|dup)'
zstyle ':completion:*:*:hx:*' file-sort modification
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent)"
fi
# fg when pressing Ctrl+Z
function fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
if [[ $(jobs | wc -l) -gt 0 ]]; then
BUFFER='fg'
zle accept-line
fi
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
# Show backgrounded jobs in fzf
j() {
jobids=$(jobs)
if [ -z "$jobids" ]
then
echo "No background jobs!"
return
fi
id=$(echo $jobids | fzf | sed -nr 's/^\[([0-9]+)\].*/\1/p')
fg %${id}
}
# Aliases
alias ls='ls --color=auto'
alias l="ls -haltr"
alias ll="ls -haltr"
alias xclip='xclip -selection clipboard'
alias view='nvim -R'
function nrg {
results=$(rg --vimgrep $@)
if [ $? -eq 0 ]; then
nvim -q <(echo $results) -c 'copen'
else
echo "\033[0;31mNo results\033[0m"
fi
}
function try {
while "$@"; do :; done
}
# Suffix aliases
alias -s py=nvim
alias -s sv=nvim
alias -s v=nvim
alias -s vhd=nvim
alias -s sh=nvim
setopt extendedglob
typeset -Ag abbreviations
abbreviations=(
# "ac" "ack -C 5__CURSOR__--ignore-dir=.build"
"Ig" "| rg"
"Ip" "| $PAGER"
"Ih" "| head"
"Ik" "| keep"
"It" "| tail"
"Is" "| sort"
"Iv" "| ${VISUAL:-${EDITOR}}"
"Iw" "| wc"
"Ix" "| xargs"
"Ic" "| clip"
"psa" "ps -ax -o pid,pgid,user,start_time,time,command | rg"
)
magic-abbrev-expand() {
local MATCH
LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
command=${abbreviations[$MATCH]}
LBUFFER+=${command:-$MATCH}
if [[ "${command}" =~ "__CURSOR__" ]]
then
RBUFFER=${LBUFFER[(ws:__CURSOR__:)2]}
LBUFFER=${LBUFFER[(ws:__CURSOR__:)1]}
else
zle self-insert
fi
}
no-magic-abbrev-expand() {
LBUFFER+=' '
}
zle -N magic-abbrev-expand
zle -N no-magic-abbrev-expand
bindkey " " magic-abbrev-expand
bindkey "^x " no-magic-abbrev-expand
bindkey -M isearch " " self-insert
# Exports
export XDG_CONFIG_HOME=$HOME/.config
export PATH=$HOME/bin:$PATH
export PATH=$HOME/.local/bin:$PATH
export MANPATH=$HOME/.local/man:$MANPATH
export EDITOR=hx
export HGEDITOR=hx
export RIPGREP_CONFIG_PATH=$HOME/.config/ripgrep/ripgreprc
export BAT_CONFIG_PATH=$HOME/.config/bat/config
export PS_FORMAT='pid,pgid,state,start_time,%cpu,command'
if [ -z "$GPG_TTY" ]; then
export GPG_TTY=$(tty)
fi
export ZK_NOTEBOOK_DIR=$HOME/notebook
autoload -U compinit
for dump in ~/.zcompdump(N.mh+24); do
compinit
done
compinit -C
[ -f ~/.zshrc.local ] && source ~/.zshrc.local
if [ -f "$HOME/bin/rtx" ]; then
eval "$($HOME/bin/rtx activate zsh)"
eval "$($HOME/bin/rtx hook-env)"
fi
export SUDO_EDITOR=$(which hx)
eval "$(direnv hook zsh)"
zstyle ':completion:*:descriptions' format '[%d]'
zsh-defer source ~/.zsh/zsh-history-substring-search.zsh
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=cyan,fg=white'
zsh-defer source ~/.zsh/zsh-autosuggestions.zsh
zsh-defer source ~/.zsh/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
export HISTDB_FILE="${HOME}/.histdb/zsh-history-$(hostname).db"
export HISTDB_HEIGHT="70%"
zsh-defer source ~/.zsh/zsh-histdb/sqlite-history.zsh
zsh-defer source ~/.zsh/zsh-histdb-skim/zsh-histdb-skim.zsh
zsh-defer source ~/.zsh/jq-zsh-plugin/jq.plugin.zsh
source ~/.config/zsh/fzf/colors.zsh
unix-word-rubout() {
local WORDCHARS=$'!"#$%&\'()*+,-.:;<=>?@[\\]^_`{|}~'
zle backward-kill-word
}
# The plugin will auto execute this zvm_after_init function
function zvm_after_init() {
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
bindkey '^r' histdb-skim-widget
# Postpone current command to next prompt
bindkey '^t' push-line-or-edit
# Cut current command into killring
bindkey '^u' backward-kill-line
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
bindkey '^p' history-substring-search-up
bindkey '^n' history-substring-search-down
bindkey '^f' autosuggest-accept
zle -N unix-word-rubout
bindkey '^w' unix-word-rubout
bindkey '^[f' insert-last-word
bindkey '^[x' execute-named-cmd
}
zsh-defer source ~/.zsh/zsh-vi-mode.zsh
_zsh_autosuggest_strategy_histdb_top_here() {
local query="select commands.argv from
history left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where places.dir LIKE '$(sql_escape $PWD)%'
and commands.argv LIKE '$(sql_escape $1)%'
group by commands.argv order by count(*) desc limit 1"
suggestion=$(_histdb_query "$query")
}
ZSH_AUTOSUGGEST_STRATEGY=histdb_top_here
if [ ${TMUX} ]; then
unset zle_bracketed_paste
fi
# Deduplicate PATH
typeset -U path