forked from peikk0/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
345 lines (275 loc) · 10.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
# {{{ General settings
# History
HISTFILE="${HOME}/.zsh_history"
HISTSIZE=5000
SAVEHIST=5000
setopt append_history hist_ignore_all_dups hist_reduce_blanks
# Misc options
setopt auto_list
setopt auto_param_keys
setopt auto_param_slash
setopt autocd
setopt equals
setopt extended_glob
setopt hash_cmds
setopt hash_dirs
setopt numeric_glob_sort
setopt transient_rprompt
unsetopt beep
unsetopt notify
# Color vars
autoload -U colors
colors
# Watch for login/logout
watch=all
# }}}
# {{{ Keybindings
# emacs keybindings, tired of vi mode in shell
bindkey -e
# Fixes from Debian
if [[ "${TERM}" != emacs ]]; then
[[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
[[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
[[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
[[ -z "$terminfo[kich1]" ]] || bindkey -M emacs "$terminfo[kich1]" overwrite-mode
[[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
[[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
[[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
[[ -z "$terminfo[kich1]" ]] || bindkey -M vicmd "$terminfo[kich1]" overwrite-mode
# [[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
[[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" up-line-or-history
[[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
# [[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
[[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" up-line-or-history
# [[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
[[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" down-line-or-history
[[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
[[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
# ncurses fogyatekos
# [[ "$terminfo[kcuu1]" == "\eO"* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
# [[ "$terminfo[kcud1]" == "\eO"* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
# [[ "$terminfo[kcuu1]" == ""* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" up-line-or-history
# [[ "$terminfo[kcud1]" == ""* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" down-line-or-history
[[ "$terminfo[kcuf1]" == "\eO"* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
[[ "$terminfo[kcub1]" == "\eO"* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
[[ "$terminfo[khome]" == "\eO"* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
[[ "$terminfo[kend]" == "\eO"* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
[[ "$terminfo[khome]" == "\eO"* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
[[ "$terminfo[kend]" == "\eO"* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
fi
# URxvt keys
bindkey "\e[2~" overwrite-mode
bindkey "\e[3~" delete-char
bindkey "\e[7~" beginning-of-line
bindkey "\e[8~" end-of-line
bindkey "\e[5~" history-search-backward
bindkey "\e[6~" history-search-forward
# Man
bindkey "\eh" run-help
# Edit cmdline
autoload edit-command-line
zle -N edit-command-line
bindkey "\ee" edit-command-line
bindkey "\ex" execute-named-cmd
# Complete help
bindkey "\ec" _complete_help
# () [] {} ...
# bindkey -s '((' '()\ei'
# bindkey -s '( (' '( )\ehhi'
# bindkey -s '(((' '(\ea( ))\ehhhi'
# bindkey -s '{{' '{}\ei'
# bindkey -s '{ {' '{ }\ehi'
# bindkey -s '{{{' '{\ea{ }}\ehhhi' # }}} (quick and ugly folding fix...)
# bindkey -s '[[' '[]\ei'
# bindkey -s '[ [' '[ ]\ehhi'
# bindkey -s '[[[' '[\ea[ ]]\ehhhi'
# bindkey -s "''" "'\ea'\ei"
# bindkey -s '""' '"\ea"\ei'
# }}}
# {{{ Completion
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit
autoload -Uz complist
compinit
zstyle ':completion:*' menu select=5
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' completer _complete _correct _approximate
zstyle ':completion:*' max-errors 2 not-numeric
zstyle ':completion:*:approximate:::' max-errors 3 numeric
zstyle ':completion:*' group-name ''
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' original true
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*:rm:*' ignore-line yes
# }}}
# {{{ Per OS settings
case `uname -s` in
FreeBSD|Darwin)
ZCOLORS="no=00:fi=00:di=00;34:ln=00;36:pi=00;32:so=00;35:do=00;35:bd=00;33:cd=00;33:or=05;37;41:mi=05;37;41:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=00;32:"
zstyle ':completion:*' list-colors ${(s.:.)ZCOLORS}
;;
Linux)
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
;;
esac
# }}}
# {{{ title()
# Display the title
function update_title {
local t="%m %~ %#"
case ${TERM} in
screen*) # and tmux
print -nP "\ek$t\e\\"
print -nP "\e]0;$t\a"
;;
xterm*|rxvt*|stterm*|(E|e)term)
print -nP "\e]0;$t\a"
;;
esac
}
autoload -U add-zsh-hook
add-zsh-hook precmd update_title
# }}}
# {{{ Prompts
function simple_prompt {
# Color for non-text things
local _reset_color="%{${reset_color}%}"
local _misc_color="%{${fg_no_bold[white]}%}"
local _rcerr_color="%{${fg_no_bold[red]}%}"
local _desk_color="%{${fg_no_bold[blue]}%}"
local _host_color="%{${fg_no_bold[cyan]}%}"
# Change path color given user rights on it
if [[ -O "${PWD}" ]]; then # owner
local _path_color="%{${fg_bold[yellow]}%}"
elif [[ -w "${PWD}" ]]; then # can write
local _path_color="%{${fg_bold[blue]}%}"
else # other
local _path_color="%{${fg_bold[red]}%}"
fi
if [[ ${UID} = 0 ]]; then
local _sign_color="%{${fg_bold[red]}%}"
else
local _sign_color="%{${fg_bold[green]}%}"
fi
# Display return code when not 0
local return_code="%(?..${_misc_color}!${_rcerr_color}%?${_misc_color}! )"
# Host
local host="${_host_color}%m"
# Desk
if [ -n "${DESK_NAME}" ]; then
local desk=" ${_misc_color}[${_desk_color}${DESK_NAME}${_misc_color}]"
else
local desk=""
fi
# Current path
local cwd="${_path_color}%48<...<%~"
# Red # for root, green % for user
local sign="${_sign_color}%#"
# Set the prompt
PS1="${return_code}${host} ${cwd}${desk} ${sign}${_reset_color} "
# Right prompt with clock
RPS1=" %{$fg_no_bold[yellow]%}%D{%d/%m/%y %H:%M:%S}%{${reset_color}%}"
# Others prompts
PS2="%{$fg_no_bold[yellow]%}%_>%{${reset_color}%} "
PS3="%{$fg_no_bold[yellow]%}?#%{${reset_color}%} "
}
POWERLEVEL9K_THEME="${HOME}/.zsh/powerlevel9k/powerlevel9k.zsh-theme"
setup_powerlevel9k() {
POWERLEVEL9K_MODE="nerdfont-complete"
POWERLEVEL9K_IGNORE_TERM_COLORS=true
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=2
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=2
POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR=$'\uE0C6'
POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR=$'\uE0C6'
POWERLEVEL9K_LEFT_SEGMENT_END_SEPARATOR=" "
POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR=$'\uE0C7'
POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR=$'\uE0C7'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon context dir dir_writable vcs desk aws)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time background_jobs time date_joined)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right"
POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S}"
POWERLEVEL9K_DATE_FORMAT="%D{%Y-%m-%d}"
DEFAULT_USER="pierre"
POWERLEVEL9K_DESKTOP_ICON=$'\uF108'
# base16 colors
POWERLEVEL9K_OS_ICON_BACKGROUND='018'
POWERLEVEL9K_OS_ICON_FOREGROUND='021'
POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND='green'
POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND='018'
POWERLEVEL9K_CONTEXT_REMOTE_BACKGROUND='green'
POWERLEVEL9K_CONTEXT_REMOTE_FOREGROUND='018'
POWERLEVEL9K_CONTEXT_REMOTE_SUDO_BACKGROUND='red'
POWERLEVEL9K_CONTEXT_REMOTE_SUDO_FOREGROUND='021'
POWERLEVEL9K_CONTEXT_SUDO_BACKGROUND='red'
POWERLEVEL9K_CONTEXT_SUDO_FOREGROUND='021'
POWERLEVEL9K_CONTEXT_ROOT_BACKGROUND='red'
POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND='021'
POWERLEVEL9K_DIR_HOME_BACKGROUND='019'
POWERLEVEL9K_DIR_HOME_FOREGROUND='blue'
POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND='019'
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND='blue'
POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='019'
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='021'
POWERLEVEL9K_DIR_ETC_BACKGROUND='019'
POWERLEVEL9K_DIR_ETC_FOREGROUND='021'
POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_BACKGROUND='red'
POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_FOREGROUND='016'
POWERLEVEL9K_VCS_CLEAN_BACKGROUND='green'
POWERLEVEL9K_VCS_CLEAN_FOREGROUND='018'
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='teal'
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='018'
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='016'
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='018'
POWERLEVEL9K_DESK_BACKGROUND='017'
POWERLEVEL9K_DESK_FOREGROUND='021'
POWERLEVEL9K_AWS_BACKGROUND='red'
POWERLEVEL9K_AWS_FOREGROUND='021'
POWERLEVEL9K_STATUS_ERROR_BACKGROUND='018'
POWERLEVEL9K_STATUS_ERROR_FOREGROUND='red'
POWERLEVEL9K_STATUS_OK_BACKGROUND='018'
POWERLEVEL9K_STATUS_OK_FOREGROUND='green'
POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND='red'
POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND='021'
POWERLEVEL9K_BACKGROUND_JOBS_BACKGROUND='017'
POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND='021'
POWERLEVEL9K_TIME_BACKGROUND='019'
POWERLEVEL9K_TIME_FOREGROUND='020'
POWERLEVEL9K_DATE_BACKGROUND='019'
POWERLEVEL9K_DATE_FOREGROUND='020'
prompt_desk() {
if [[ -n "$DESK_NAME" ]]; then
"$1_prompt_segment" "$0" "$2" black cyan "$DESK_NAME" DESKTOP_ICON
fi
}
. "${POWERLEVEL9K_THEME}"
}
if [[ -e "${POWERLEVEL9K_THEME}" ]]; then
setup_powerlevel9k
else
add-zsh-hook precmd simple_prompt
fi
# }}}
# {{{ run-help-sudo
function run-help-sudo {
if [ $# -eq 0 ]; then
man sudo
else
man $1
fi
}
# }}}
# {{{ Local configuration
if [[ -f "${HOME}/.zshrc.local" ]]; then
. "${HOME}/.zshrc.local"
fi
# }}}
# {{{ Syntax highlighting
if [[ -f "${HOME}/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]]; then
. "${HOME}/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
fi
# }}}
: # noop
# vim:filetype=zsh:tabstop=2:shiftwidth=2:fdm=marker: