-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy path.zshrc
390 lines (294 loc) · 9.3 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
#####################################################################
# init
#####################################################################
# Profile.
#zmodload zsh/zprof && zprof
#zmodload zsh/datetime
#setopt promptsubst
#PS4='+$EPOCHREALTIME %N:%i> '
#exec 3>&2 2>/tmp/zsh_profile.$$
#setopt xtrace prompt_subst
if [ ! -f ~/.zshrc.zwc -o ~/.zshrc -nt ~/.zshrc.zwc ]; then
zcompile ~/.zshrc
# Compile all zsh plugins
if [ -d ~/.zsh ]; then
for f in $(find ~/.zsh -type f -name "*.zsh"); do zcompile $f; done
fi
fi
source ~/.zshenv
#####################################################################
# environment
#####################################################################
export EDITOR=nvim
export LANG=en_US.UTF-8
# Better umask
umask 022
WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'
# Improved less option
export LESS='--tabs=4 --no-init --LONG-PROMPT --quit-if-one-screen --RAW-CONTROL-CHARS'
# Print core files?
#unlimit
#limit core 0
#limit -s
#limit coredumpsize 0
#####################################################################
# completions
#####################################################################
# Enable completions
if [ -d ~/.zsh/comp ]; then
fpath=(~/.zsh/comp $fpath)
autoload -U ~/.zsh/comp/*(:t)
fi
zstyle ':completion:*' group-name ''
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:descriptions' format '%d'
zstyle ':completion:*:options' verbose yes
zstyle ':completion:*:values' verbose yes
zstyle ':completion:*:options' prefix-needed yes
# Use cache completion
# apt-get, dpkg (Debian), rpm (Redhat), urpmi (Mandrake), perl -M,
# bogofilter (zsh 4.2.1 >=), fink, mac_apps...
# zstyle ':completion:*' use-cache true
zstyle ':completion:*:default' menu select=1
zstyle ':completion:*' matcher-list \
'' \
'm:{a-z}={A-Z}' \
'l:|=* r:|[.,_-]=* r:|=* m:{a-z}={A-Z}'
# sudo completions
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin \
/usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin
zstyle ':completion:*' menu select
zstyle ':completion:*' keep-prefix
zstyle ':completion:*' completer _oldlist _complete _match _ignored \
_approximate _list _history
autoload -Uz compinit && compinit -C
zstyle ':completion:*:processes' command \
"ps -u $USER -o pid,stat,%cpu,%mem,cputime,command"
# Enable auto-suggestion
# https://github.com/zsh-users/zsh-autosuggestions
if [ -d ~/.zsh/zsh-autosuggestions ]; then
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#666666,bg=#2c2c2c"
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
fi
#####################################################################
# colors
#####################################################################
# Color settings for zsh complete candidates
alias ls='ls -F --show-control-chars --color=always'
alias la='ls -aF --show-control-chars --color=always'
alias ll='ls -lF --show-control-chars --color=always'
export LSCOLORS=ExFxCxdxBxegedabagacad
export LS_COLORS=\
'di=01;34:ln=01;35:so=01;32:ex=01;31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30'
zstyle ':completion:*' list-colors \
'di=;34;1' 'ln=;35;1' 'so=;32;1' 'ex=31;1' 'bd=46;34' 'cd=43;34'
# Use prompt colors feature
autoload -U colors
colors
# Use git-prompt.zsh instead of vcs_info
# https://github.com/woefe/git-prompt.zsh
if [ -d ~/.zsh/git-prompt.zsh ]; then
source ~/.zsh/git-prompt.zsh/git-prompt.zsh
fi
ZSH_GIT_PROMPT_SHOW_UPSTREAM="no"
ZSH_THEME_GIT_PROMPT_PREFIX=" "
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_SEPARATOR="|"
ZSH_THEME_GIT_PROMPT_DETACHED="%{$fg_bold[cyan]%}:"
ZSH_THEME_GIT_PROMPT_BRANCH="%{$fg_bold[magenta]%}"
ZSH_THEME_GIT_PROMPT_UPSTREAM_SYMBOL="%{$fg_bold[yellow]%}⟳ "
ZSH_THEME_GIT_PROMPT_UPSTREAM_PREFIX="%{$fg[red]%}(%{$fg[yellow]%}"
ZSH_THEME_GIT_PROMPT_UPSTREAM_SUFFIX="%{$fg[red]%})"
ZSH_THEME_GIT_PROMPT_BEHIND="↓"
ZSH_THEME_GIT_PROMPT_AHEAD="↑"
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[red]%}X"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg[green]%}O"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg[red]%}+"
ZSH_THEME_GIT_PROMPT_UNTRACKED="…"
ZSH_THEME_GIT_PROMPT_STASHED="%{$fg[blue]%}⚑"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✔"
if [ $UID = "0" ]; then
PROMPT=$'%B%{\e[31m%}%/#%{\e[m%}%b '
else;
if [ -n "${REMOTEHOST}${SSH_CONNECTION}" ]; then
PROMPT=$'%{\e[37m%}${HOST%%.*} '
else
PROMPT=""
fi
PROMPT+=$'%{\e[33m%}[%35<..<%~]%{\e[m%}$(gitprompt)'
PROMPT+=$'%(?.%(!.%F{white}%F{yellow}%F{red}.%F{green})%f.%F{red}%f)\n'
PROMPT+=$'%{\e[$[31+$RANDOM % 7]m%}%U%B%#'"%b%{%}%u "
fi
# Multi line prompt
PROMPT2="%_%% "
# Spell miss prompt
SPROMPT="correct> %R -> %r [n,y,a,e]? "
# Enable syntax highlight
# https://github.com/zdharma-continuum/fast-syntax-highlighting
if [ -d ~/.zsh/fast-syntax-highlighting ]; then
source ~/.zsh/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
fi
#####################################################################
# options
######################################################################
setopt auto_resume
# Ignore <C-d> logout
setopt ignore_eof
# Disable beeps
setopt no_beep
# {a-c} -> a b c
setopt brace_ccl
# Enable spellcheck
setopt correct
# Enable "=command" feature
setopt equals
# Disable flow control
setopt no_flow_control
# Ignore dups
setopt hist_ignore_dups
# Reduce spaces
setopt hist_reduce_blanks
# Ignore add history if space
setopt hist_ignore_space
# Save time stamp
setopt extended_history
# Expand history
setopt hist_expand
# Better jobs
setopt long_list_jobs
# Enable completion in "--option=arg"
setopt magic_equal_subst
# Add "/" if completes directory
setopt mark_dirs
# Disable menu complete for vimshell
setopt no_menu_complete
setopt list_rows_first
# Expand globs when completion
setopt glob_complete
# Enable multi io redirection
setopt multios
# Can search subdirectory in $PATH
setopt path_dirs
# For multi byte
setopt print_eightbit
# Print exit value if return code is non-zero
setopt print_exit_value
setopt pushd_ignore_dups
setopt pushd_silent
# Short statements in for, repeat, select, if, function
setopt short_loops
# Ignore history (fc -l) command in history
setopt hist_no_store
unsetopt promptcr
setopt hash_cmds
setopt numeric_glob_sort
# Enable comment string
setopt interactive_comments
# Improve rm *
setopt rm_star_wait
# Enable extended glob
setopt extended_glob
# Note: It is a lot of errors in script
# setopt no_unset
# Prompt substitution
setopt prompt_subst
setopt always_last_prompt
# List completion
setopt auto_list
setopt auto_param_slash
setopt auto_param_keys
# List like "ls -F"
setopt list_types
# Compact completion
setopt list_packed
setopt auto_cd
setopt auto_pushd
setopt pushd_minus
setopt pushd_ignore_dups
# Check original command in alias completion
setopt complete_aliases
unsetopt hist_verify
# Enable suffix completion
setopt complete_in_word
# Histories
HISTFILE=$HOME/.zsh-history
HISTSIZE=3000
SAVEHIST=8000
setopt inc_append_history
# Ignore some command histories
export HISTORY_IGNORE="(cd|pwd|l[sal]|rm|mv|shutdown|exit|rmdir)"
# Enable math functions
zmodload zsh/mathfunc
#####################################################################
# alias
######################################################################
# Better mv, cp, mkdir
alias mv='nocorrect mv'
alias cp='nocorrect cp'
alias mkdir='nocorrect mkdir'
# Improve du, df
alias du='du -h'
alias df='df -h'
# Improve od for hexdump
alias od='od -Ax -tx1z'
alias hexdump='hexdump -C'
# Minimal Neovim
alias nvim='nvim \
-V0 -n -u NONE --noplugin -S $HOME/.config/nvim/init.vim \
$( [ ! -e $HOME/.cache/nvim/server.pipe ] && \
echo "--listen $HOME/.cache/nvim/server.pipe" )'
# Use Vim server feature
alias vim='vim --servername vim'
#####################################################################
# keybinds
######################################################################
# emacs keybinds
bindkey -e
# History completion
autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^p" history-beginning-search-backward-end
bindkey "^n" history-beginning-search-forward-end
# Like bash
bindkey "^u" backward-kill-line
# Use clipboard for yank
x-yank () {
CUTBUFFER=$(xclip -selection clipboard -o -b </dev/null)
zle yank
}
zle -N x-yank
bindkey "^y" x-yank
# Edit command line by the editor
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey "^O" edit-command-line
#####################################################################
# others
######################################################################
# Improved terminal title.
case "${TERM}" in
kterm*|xterm*|vt100|st*|rxvt*|alacritty)
precmd() {
echo -ne "\033]0;${USER}@${HOST%%.*}:${PWD}\007"
}
;;
esac
# Use dtach or abduco instead screen/tmux
# C-\ is detach
# dtach command, dtach -A command, dtach -a session
# adbuco -c session,abduco -c session command, abduco -a command
# Use mise
# https://github.com/jdxcode/mise
if [ -x ~/.local/bin/mise ]; then
#eval "$(~/.local/bin/mise activate zsh)"
if ! [ -f /tmp/mise.cache ]; then
~/.local/bin/mise activate zsh > /tmp/mise.cache
zcompile /tmp/mise.cache
fi
source /tmp/mise.cache
fi
if ( which zprof > /dev/null ); then
zprof | less
fi