forked from tnaglo/zshconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc.core
369 lines (313 loc) · 11.8 KB
/
.zshrc.core
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
############### backspace fix ########
stty erase ""
############### colors ###############
LS_COLORS=''
LS_COLORS=$LS_COLORS:'no=00' # Normal text = Default foreground
LS_COLORS=$LS_COLORS:'fi=00' # Regular file = Default foreground
LS_COLORS=$LS_COLORS:'di=01;36' # Directory = Bold, Yellow
LS_COLORS=$LS_COLORS:'ln=35' # Symbolic link = Bold, Cyan
LS_COLORS=$LS_COLORS:'pi=33' # Named pipe = Yellow
LS_COLORS=$LS_COLORS:'so=01;35' # Socket = Bold, Magenta
LS_COLORS=$LS_COLORS:'do=01;35' # DO = Bold, Magenta
LS_COLORS=$LS_COLORS:'bd=01;37' # Block device = Bold, Grey
LS_COLORS=$LS_COLORS:'cd=34;43' # Character device = Bold, Grey
LS_COLORS=$LS_COLORS:'ex=01' # Executable file = Bold, Green
############### exports ###############
export LC_CTYPE='en_US.UTF-8'
export LANG='en_US.UTF-8'
export APPEND_HISTORY
export HISTFILE=~/.zsh_history
export HISTSIZE=5000
export SAVEHIST=5000
export LS_COLORS
export DIRSTACKSIZE=16
############### setopts ###############
setopt extended_glob
setopt APPEND_HISTORY
setopt AUTO_PARAM_SLASH
setopt AUTO_PUSHD
setopt BASH_AUTO_LIST
setopt BEEP
setopt FLOW_CONTROL
setopt HIST_IGNORE_DUPS
setopt HIST_FIND_NO_DUPS
setopt LIST_TYPES
setopt MARK_DIRS
setopt NO_AUTO_MENU
setopt NO_HIST_NO_STORE
setopt NO_MENU_COMPLETE
setopt NOTIFY
setopt PROMPT_SUBST
setopt RM_STAR_SILENT
setopt TRANSIENT_RPROMPT
setopt ZLE
############### bindkeys ##############
bindkey "\eOH" beginning-of-line
bindkey "\e[1~" beginning-of-line
bindkey "\e[H" beginning-of-line
bindkey "\eOF" end-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[F" end-of-line
bindkey "^[[1;3C" forward-word # [Alt-RightArrow] - move forward one word
bindkey '[C' forward-word # [Alt-RightArrow] - move forward one word MacOS
bindkey "^[[1;3D" backward-word # [Alt-LeftArrow] - move backward one word
bindkey '[D' backward-word # [Alt-LeftArrow] - move backward one word MacOS
bindkey "\e[3~" delete-char-or-list
bindkey "" delete-char-or-list
bindkey "OM" accept-line
bindkey "^A" beginning-of-line
bindkey "^D" delete-char-or-list
bindkey "^E" end-of-line
bindkey "^G" send-break
# [Backspace] - delete backward
bindkey -M emacs '^?' backward-delete-char
bindkey -M viins '^?' backward-delete-char
bindkey -M vicmd '^?' backward-delete-char
bindkey '^?' backward-delete-char
bindkey "^I" expand-or-complete
bindkey "^J" accept-line
bindkey "^K" kill-line
bindkey "^L" clear-screen
bindkey "^M" accept-line
bindkey "^N" down-line-or-history
bindkey "^O" accept-line-and-down-history
bindkey "^P" up-line-or-history
bindkey "^Q" push-line
bindkey "^R" history-incremental-search-backward
bindkey "^S" history-incremental-search-forward
bindkey "^T" transpose-chars
bindkey "^U" kill-whole-line
bindkey "^V" quoted-insert
bindkey "^W" backward-kill-word
bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward
############### aliases ###############
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'
UNAMESTR=`uname`
if [ $UNAMESTR = 'Darwin' ]
then
alias ls='ls -F'
alias ps='ps auxw'
else
alias ls='ls --color=yes -F'
alias ps='ps aufwx'
fi
alias l='ls -alh'
alias ll='ls -lh'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../../
alias cdd='cd -' # goto last dir cd'ed from
alias z='vim ~/.zsh/.zshrc.core && source ~/.zshrc'
alias vim='vim -o'
# screen
# alias sls='screen -ls'
# alias sr='screen -dRR'
# alias ss='screen -S'
# alias sx='screen -x'
# git
alias g='git status'
alias gx='git checkout'
alias gf='git fetch'
alias gp='git pull'
alias gP='git push'
alias gm='git merge'
alias gmm='git merge master'
alias ga='git add'
alias gaa='git add -A'
alias gcm='git commit'
alias gcma='git commit --amend'
alias gclb="git remote prune origin && git branch -vv | grep 'origin/.*: gone]' | awk '{print \$1}' | xargs git branch -d"
alias gd='git diff --color'
alias gdc='git diff --color --cached'
alias gdw='git diff -w'
alias gb='git branch -vv'
alias gba='git branch -avv'
alias gl='git log --stat --color'
alias glp='git log -p --color'
alias glpw='git log -p -w --color'
alias gr='git rebase'
alias grc='git rebase --continue'
alias gra='git rebase --abort'
alias grs='git rebase --skip'
alias grom='git rebase origin/master'
alias gsu='git submodule update'
alias devopsrepo='cd ~/xempusgit/plat/devops'
alias managerrepo='cd ~/xempusgit/xbm/manager'
# alias ^H='stty erase ^H'
# alias ^?='stty errase ^?'
############### functions #############
# git
function gri() {
if [[ -z "$1" ]]; then
git rebase -i --autosquash `git merge-base master HEAD`
else
git rebase -i --autosquash HEAD~$1
fi
}
#zsh-completions
fpath=(plugins/zsh-completions/src $fpath)
############### modules ###############
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
(( count = $count + 1 ))
done
PR_NO_COLOUR="%{$terminfo[sgr0]%}"
autoload -U compinit promptinit zargs
compinit -C
promptinit
# Set default completion to look through all files, then
# the command history.
compctl -D -f + -H 0 '' -X '(No file found; using history)'
compctl -o setopt
compctl -v echo export
compctl -z -P '%' bg
compctl -j -P '%' fg jobs disown
compctl -j -P '%' + -s '`ps -x | tail +2 | cut -c1-5`' wait
compctl -A shift
compctl -c type whence where which whereis killall man apropos
zstyle ':completion:*' completer _expand _complete _complete:-extended _prefix
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:correct:*' menu yes select
zstyle ':completion:*:correct:*' max-errors 2 numeric
zstyle ':completion:*:approximate:*' max-errors 2 numeric
zstyle ':completion:*:correct:*' insert-unambiguous true
zstyle ':completion:*:correct:*' original true
zstyle ':completion:*:expand:*' group-order all-expansions expansions
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'
zstyle ':completion:lappr:*' completer _approximate
zstyle ':completion:lappr:*:approximate:*' max-errors 3 numeric
zstyle ':completion:lamatch:*' completer _all_matches
zstyle ':completion:lamatch:*' old-matches only
zstyle ':completion:lhist:*' completer _history
zstyle ':completion:*:match:*' match-original non-empty-value
zstyle ':completion:*' ambiguous true
zstyle ':completion:*' glob true
zstyle ':completion:*' word true
zstyle ':completion:*:complete-extended:*' matcher-list \
'm:{a-z}={A-Z}' 'r:|[+._-]=*' # lowercase matches uppercase,
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
zstyle ':completion:*' menu select=2
zstyle ':completion:*' select-prompt '%SSelect: lines: %L matches: %M [%p]'
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:cd:*' tag-order \
local-directories directory-stack named-directories path-directories
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format \
"${PR_LIGHT_RED}completing %B%d%b%$PR_NO_COLOUR"
zstyle ':completion:*:corrections' format "${PR_LIGHT_RED}%d (errors: %e)%}"
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' ignore-parents pwd parent ..
zstyle ':completion:*' select-scroll -1
zstyle ':completion:*' range 200:20
zstyle ':completion:*' keep-prefix changed
zstyle ':completion:*:warnings' format \
"$PR_LIGHT_RED}No matches for:$PR_NO_COLOUR %d"
compdef _man man pinfo
zstyle ':completion:*:-tilde-:*' group-order \
'named-directories' 'path-directories' 'users' 'expand'
## Prevent CVS files/directories from being completed
zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'
# With commands like rm it's annoying if one gets offered the same filename
# again even if it is already on the command line. To avoid that:
zstyle ':completion:*:rm:*' ignore-line yes
#menus
zstyle ':completion:*:*:ssh:*' menu yes select
zstyle ':completion:*:*:scp:*' menu yes select
zstyle ':completion:*:*:ncftp:*' menu yes select
zstyle ':completion:*:*:telnet:*' menu yes select
# When completing process IDs I normally want to fall into menu selection, too:
zstyle ':completion:*:kill:*' command 'ps -U $USER -ww -O pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*:kill:*' insert-ids single
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
# when completing inside array or association subscripts, the array elements are more useful than parameters so complete them first:
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# If you end up using a directory as argument, this will remove the trailing slash (usefull in ln)
zstyle ':completion:*' squeeze-slashes true
# color completion
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31"
# Ignore completion functions for commands you don't have:
zstyle ':completion:*:functions' ignored-patterns '_*'
compctl -s '$(groups)' + -k groups newgrp
compctl -f -x 'p[1], p[2] C[-1,-*]' -k groups -- chgrp
compctl -f -x 'p[1] n[-1,.], p[2] C[-1,-*] n[-1,.]' -k groups - \
'p[1], p[2] C[-1,-*]' -u -S '.' -q -- chown
compctl -g "*.bz2" + -g "*(-/) .*(-/)" bunzip2
compctl -g "*.rpm" + -g "*(-/) .*(-/)" rpm2cpio rpm
compctl -g "*.c" + -g "*(-/) .*(-/)" gcc cc
compctl -g "*.cc *.CC *.cpp *.C" + -g "*(-/) .*(-/)" g++ CC
compctl -g "*.gr" + -g "*(-/) .*(-/)" groff
compctl -g "*.gz" + -g "*(-/) .*(-/)" gunzip
compctl -g "*.gz *.Z *.zip" + -g "*(-/) .*(-/)" zless zgrep
compctl -g "*.zip" + -g "*(-/) .*(-/)" unzip
compctl -g "*.Z" + -g "*(-/) .*(-/)" uncompress
compctl -g "*.tar *.tgz *.tz *.tar.Z *.tar.bz2 *.tZ *.tar.gz" \
+ -g "*(-/) .*(-/)" tar
compctl -g "*.html *.htm" + -g "*(-/) .*(-/)" + -H 0 ''\
lynx wget links w3m
compctl -g "*(-/) .*(-/)" cd rmdir
############### git prompt ###########
source ~/.zsh/plugins/zsh-git-prompt/zshrc.sh
if command -v kubectl > /dev/null; then
############ kubectl completion ######
source <(kubectl completion zsh)
fi
########### powerlevel 10k ###########
source ~/.zsh/themes/powerlevel10k/powerlevel10k.zsh-theme
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.zsh/.p10k.zsh ]] || source ~/.zsh/.p10k.zsh
######## terraform completion #######
if command -v terraform > /dev/null; then
complete -o nospace -C $(which terraform) terraform
fi
ZSH_THEME_GIT_PROMPT_CONFLICTS="%{$fg_bold[red]%}✖"
ZSH_THEME_GIT_PROMPT_CHANGED="%{$fg_bold[blue]%}✚"
setopt promptsubst
setopt promptpercent
if [ "$EUID" -ne 0 ]
then
PROMPT='
%{$fg[magenta]%}%n%{$reset_color%}@%{$fg[yellow]%}%M%{$reset_color%}: %{$fg_bold[green]%}%~%{$reset_color%} $(git_super_status)
> '
else
PROMPT='
%{$fg[red]%}%n%{$reset_color%}@%{$fg[yellow]%}%M%{$reset_color%}: %{$fg_bold[green]%}%~%{$reset_color%} $(git_super_status)
> '
fi
if [[ ${TERM} == "screen-bce" || ${TERM} == "screen" ]]; then
precmd () { print -Pn "\033k\033\134\033k%m[%1d]\033\134" }
preexec () { print -Pn "\033k\033\134\033k%m[$1]\033\134" }
else
precmd () { print -Pn "\e]0;%n@%m: %~\a" }
preexec () { print -Pn "\e]0;%n@%m: $1\a" }
fi
h=()
if [[ -r ~/.ssh/config ]]; then
h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*})
fi
if [[ -r ~/.ssh/known_hosts ]]; then
h=($h ${${${(f)"$(cat ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null
fi
if [[ -r /etc/hosts ]]; then
h=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
fi
if [[ $#h -gt 0 ]]; then
zstyle ':completion:*:ssh:*' hosts $h
zstyle ':completion:*:slogin:*' hosts $h
fi