-
Notifications
You must be signed in to change notification settings - Fork 2
/
zshrc
374 lines (314 loc) · 12.9 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
# zmodload zsh/zprof
if [ -f '/etc/zprofile' ]; then
echo "/etc/zprofile is back. Delete it to keep it from trolling you."
fi
setopt NO_BEEP # Shut up.
setopt BRACE_CCL # Allow brace character class list expansion.
setopt RC_QUOTES # Allow 'Henry''s Garage' instead of 'Henry'\''s Garage'.
setopt LONG_LIST_JOBS # List jobs in the long format by default.
setopt AUTO_RESUME # Attempt to resume existing job before creating a new process.
setopt NOTIFY # Report status of background jobs immediately.
unsetopt BG_NICE # Don't run all background jobs at a lower priority.
unsetopt HUP # Don't kill jobs on shell exit.
unsetopt CHECK_JOBS # Don't report on jobs when shell exit.
setopt EXTENDED_GLOB # This is necessary for a lot of stuff.
setopt NO_CASE_GLOB # Glob without case sensitivity.
setopt MULTIOS # Write to multiple descriptors.
unsetopt CLOBBER # Do not overwrite existing files with > and >>.
# Use >! and >>! to bypass.
# Disable flow control
stty stop undef
stty start undef
# Aliases {{{
alias g='noglob mygit'
alias k='kubectl'
alias c=cd
for index ({1..9}) alias "$index"="cd +${index}"; unset index
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias l='ls -GF'
alias ll='ls -lhGF'
alias la='ls -ahGF'
alias lal='ls -lhaGF'
alias laf='ls -aGF'
alias v=vim
alias m='v -g'
alias vd='v -d'
alias vw='v -R'
alias rm='rm -i'
alias mkdir='mkdir -p'
alias md='mkdir'
alias mv='mv -i'
alias cp='cp -i'
alias d='dirs -v'
alias f=fg
alias bc='bc -q'
alias ip='curl www.icanhazip.com'
alias duh='du -ch'
# Disable globbing.
alias jq='noglob jq'
alias fc='noglob fc'
alias find='noglob find'
alias history='noglob history'
alias locate='noglob locate'
alias rsync='noglob rsync'
alias scp='noglob scp'
alias sftp='noglob sftp'
alias speedtest='wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip'
# }}}
# Colors {{{
export GREP_OPTIONS='--color=auto'
export ACK_COLOR_MATCH='red'
export LESS_TERMCAP_mb=$'\E[01;31m' # Begins blinking.
export LESS_TERMCAP_md=$'\E[0;36m' # Begins bold.
export LESS_TERMCAP_me=$'\E[0m' # Ends mode.
export LESS_TERMCAP_se=$'\E[0m' # Ends standout-mode.
export LESS_TERMCAP_so=$'\E[0;30;44m' # Begins standout-mode.
export LESS_TERMCAP_ue=$'\E[0m' # Ends underline.
export LESS_TERMCAP_us=$'\E[0;32m' # Begins underline.
if which dircolors > /dev/null; then
# GNU Core Utilities
alias ls='ls --group-directories-first'
if [[ -s "$HOME/.dir_colors" ]]; then
eval "$(dircolors "$HOME/.dir_colors")"
else
eval "$(dircolors)"
fi
alias ls="$aliases[ls] --color=auto"
else
# BSD Core Utilities
# Define colors for BSD ls.
export LSCOLORS='exfxcxdxbxGxDxabagacad'
# Define colors for the completion system.
export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:'
fi
# }}}
# Completion {{{
autoload -Uz compinit && compinit -i
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
setopt ALWAYS_TO_END # Move cursor to the end of a completed word.
setopt PATH_DIRS # Perform path search even on command names with slashes.
setopt AUTO_MENU # Show completion menu on a succesive tab press.
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash.
setopt MENU_COMPLETE # Autoselect the first completion entry.
unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor.
# Treat these characters as part of a word.
export WORDCHARS='*?_-.[]~&;!#$%^(){}<>'
# Case-insensitive (all), partial-word, and then substring completion.
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# Group matches and describe.
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f'
zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f'
zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' format ' %F{yellow}-- %d --%f'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' verbose yes
# Fuzzy match mistyped completions.
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric
# Increase the number of errors based on the length of the typed word.
zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'
# Don't complete unavailable commands.
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'
# Array completion element sorting.
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# Directories
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand'
zstyle ':completion:*' squeeze-slashes true
# History
zstyle ':completion:*:history-words' stop yes
zstyle ':completion:*:history-words' remove-all-dups yes
zstyle ':completion:*:history-words' list false
zstyle ':completion:*:history-words' menu yes
# Populate hostname completion.
zstyle -e ':completion:*:hosts' hosts 'reply=(
${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2>/dev/null)"}%%[#| ]*}//,/ }
${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*}
${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}}
)'
# Ignore multiple entries.
zstyle ':completion:*:(rm|kill|diff):*' ignore-line other
zstyle ':completion:*:rm:*' file-patterns '*:all-files'
# Kill
zstyle ':completion:*:*:*:*:processes' command 'ps -u $USER -o pid,user,comm -w'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;36=0=01'
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:*:kill:*' force-list always
zstyle ':completion:*:*:kill:*' insert-ids single
# Man
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.(^1*)' insert-sections true
# SSH/SCP/RSYNC
zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order users 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*'
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*'
# <cr> in menu selects and sends command
zmodload zsh/complist
bindkey -M menuselect '^M' .accept-line
# }}}
# Directories {{{
autoload -Uz zmv
setopt AUTO_CD # Auto changes to a directory without typing cd.
setopt AUTO_PUSHD # Push the old directory onto the stack on cd.
setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack.
setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd.
setopt PUSHD_TO_HOME # Push to home directory when no argument is given.
setopt CDABLE_VARS # Change directory to a path stored in a variable.
setopt AUTO_NAME_DIRS # Auto add variable-stored paths to ~ list.
# }}}
# Editor {{{
zmodload zsh/terminfo
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey -v
export KEYTIMEOUT=1
source $HOME/.zsh/bundle/history-substring-search/zsh-history-substring-search.zsh
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=white,fg=black'
function editor-info {
# Clean up previous $editor_info.
unset editor_info
typeset -gA editor_info
if [[ "$KEYMAP" == 'vicmd' ]]; then
zstyle -s ':keymap:command' format 'REPLY'
editor_info[keymap]="$REPLY"
else
if [[ "$ZLE_STATE" == *overwrite* ]]; then
zstyle -s ':keymap:overwrite' format 'REPLY'
editor_info[keymap]="$REPLY"
else
zstyle -s ':keymap:insert' format 'REPLY'
editor_info[keymap]="$REPLY"
fi
fi
unset REPLY
zle reset-prompt
zle -R
}
zle -N editor-info
function zle-keymap-select zle-line-init zle-line-finish {
# The terminal must be in application mode when ZLE is active for $terminfo
# values to be valid.
if (( $+terminfo[smkx] && $+terminfo[rmkx] )); then
case "$0" in
(zle-line-init)
# Enable terminal application mode.
echoti smkx
;;
(zle-line-finish)
# Disable terminal application mode.
echoti rmkx
;;
esac
fi
# Update editor information.
zle editor-info
}
zle -N zle-keymap-select
zle -N zle-line-finish
zle -N zle-line-init
# Toggles emacs overwrite mode and updates editor information.
function overwrite-mode {
zle .overwrite-mode
zle editor-info
}
zle -N overwrite-mode
# Enters vi insert mode and updates editor information.
function vi-insert {
zle .vi-insert
zle editor-info
}
zle -N vi-insert
# Moves to the first non-blank character then enters vi insert mode and updates
# editor information.
function vi-insert-bol {
zle .vi-insert-bol
zle editor-info
}
zle -N vi-insert-bol
# Enters vi replace mode and updates editor information.
function vi-replace {
zle .vi-replace
zle editor-info
}
zle -N vi-replace
bindkey -M vicmd v edit-command-line
bindkey -M viins '^A' beginning-of-line
bindkey -M viins '^B' backward-char
bindkey -M viins '^D' delete-char-or-list
bindkey -M viins '^E' end-of-line
bindkey -M viins '^F' forward-char
bindkey -M viins '^K' kill-line
bindkey -M vicmd '?' history-incremental-search-backward
bindkey -M vicmd '/' history-incremental-search-forward
bindkey -M viins '^T' transpose-chars
bindkey -M viins '^Y' yank
bindkey -M viins '^?' backward-delete-char
bindkey -M viins '^[[3~' delete-char
bindkey -M vicmd 'u' undo
bindkey -M viins '^N' history-substring-search-down
bindkey -M viins '^O' history-substring-search-up
bindkey -M vicmd '^R' redo
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
bindkey -M viins ' ' magic-space
bindkey '^[[Z' reverse-menu-complete
bindkey -M viins '^U' backward-kill-line
# }}}
# Functions {{{
func_glob='^([_.]*|prompt_*_setup)(.N:t)'
for func ($HOME/.zsh/func/$~func_glob) autoload -Uz $func; unset func func_glob
function mygit {
if [[ $# > 0 ]]; then
git $@
else
git status --short --ignore-submodules
fi
}
compdef mygit=git
function mcd {
mkdir -p "$*" && cd "$*"
}
# }}}
# History {{{
export HISTFILE="${ZDOTDIR:-$HOME}/.zhistory" # The path to the history file.
export HISTSIZE=100000 # The maximum number of events to save in the internal history.
export SAVEHIST=100000 # The maximum number of events to save in the history file.
setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history.
setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a previously found event.
setopt HIST_IGNORE_SPACE # Do not record an event starting with a space.
setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file.
setopt HIST_VERIFY # Do not execute immediately upon history expansion.
setopt NO_HIST_BEEP # Don't beep when accessing non-existent history.
# }}}
# Prompt {{{
autoload -Uz promptinit && promptinit
prompt cet
# }}}
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
source $HOME/.zsh/bundle/syntax-highlighting/zsh-syntax-highlighting.zsh
[[ -s $HOME/.zshrc.local ]] && source $HOME/.zshrc.local