-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
237 lines (209 loc) · 6 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
# vim: set foldmarker={,} foldlevel=0 foldmethod=marker :
# fpath {
fpath=(${ASDF_DIR}/completions $fpath)
# }
# options {
# see: man zshoptions
# underscores and case are ignored, so AUTO_LIST is the same as autolist
setopt interactivecomments
# setopt complete_aliases
setopt extendedglob
# report status of bg process
setopt notify
# do not exit on ctrl-d
setopt ignoreeof
# automatically list choices if multiple options match
setopt autolist
# history {
HISTFILE=$HOME/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
# append the history, dont overwrite
setopt appendhistory
# write the history directly after command
setopt incappendhistory
# share history between instances
setopt sharehistory
# also record starttime
setopt extendedhistory
# dont record dups
setopt histignoredups
# }
# movement {
# cd = pushd
setopt autopushd
# dont print stack
setopt pushdsilent
# dont swap top entries
setopt pushdtohome
# swap + / -
setopt pushdminus
# }
# }
# autoload {
# (look for function in $fpath)
autoload -Uz compinit && compinit
autoload -U bashcompinit && bashcompinit
autoload -U colors && colors
autoload -U zmv
autoload -U zargs
autoload -U history-search-end
autoload -U select-word-style
autoload -Uz edit-command-line
unalias run-help && autoload -U run-help
# }
# bindings {
bindkey -e
bindkey '\e[3~' delete-char
# start editor to edit command
# turn function into a widget and bind it to a key
zle -N edit-command-line
bindkey -M emacs '\ee' edit-command-line
# history {
bindkey '^[[5~' history-substring-search-up
bindkey '^[[6~' history-substring-search-down
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
# }
# select-word-style {
# ctrl-w removes just one part of a path, not the whole path
select-word-style bash
# }
# autosuggestion {
bindkey '^[ ' autosuggest-accept
# }
# }
# autocompletion {
autoload -U compinit
# extensions for completion lists
zmodload zsh/complist
# enable menu
zstyle ':completion*:default' menu select search
# if matches dont fit on one page, use a pager
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
# sort files by modification date
zstyle ':completion:*' file-sort modification
# show file details
zstyle ':completion:*' file-list all
# colorful file list
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# squash // and dont expand to /*/
zstyle ':completion:*' squeeze-slashes true
# enable partitial matching
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# enable verbose mode for completions
zstyle ':completion:*' verbose yes
# default completers
zstyle ':completion:*' completer _complete _approximate
# enable caching
zstyle ':completion:*' use-cache on
# group the completions
zstyle ':completion:*' group-name ''
# change format of the completions
zstyle ':completion:*:*:*:*:descriptions' format '%F{green}-- %d --%f'
zstyle ':completion:*:*:*:*:corrections' format '%F{yellow}!- %d (errors: %e) -!%f'
zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
# use q to exist this pager
bindkey -M listscroll q send-break
# use vi bindings for the menu
bindkey -M menuselect '^[' undo
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect '^n' vi-down-line-or-history
bindkey -M menuselect '^p' vi-up-line-or-history
bindkey '^[#' pound-insert
bindkey '^[+' push-line
compinit
# }
# virtualenv {
source virtualenvwrapper_lazy.sh
# }
# source additional configs {
for category in aliases settings functions completions; do
if [[ -d $HOME/.shells/common/$category/ ]]; then
for config in $HOME/.shells/common/$category/*.sh;do
source "$config"
done
fi
if [[ -d $HOME/.shells/zsh/$category/ ]]; then
for config in $HOME/.shells/zsh/$category/*.sh;do
source "$config"
done
fi
done
# others
for stuff in ~/{.profile,.alias}; do
[[ -f $stuff ]] && . $stuff
done
# }
# plugins {
plugins_dir="$HOME/.zsh/plugins"
[[ -d "$plugins_dir" ]] || mkdir -p "$plugins_dir"
additional_plugins=(
# 'https://github.com/reegnz/jq-zsh-plugin'
'https://github.com/hlissner/zsh-autopair'
'https://github.com/dadav/zsh-jump-target'
)
for plugin in $additional_plugins; do
plugin_path="$plugins_dir/${plugin##*/}"
if [[ -d "$plugin_path" ]]; then
if (( $(date +%s) > $(stat --format="%Y" "$plugin_path") + 86400 )); then
touch "$plugin_path"
git -C "$plugin_path" pull
fi
else
git clone "$plugin" "$plugin_path" &>/dev/null
fi
for p in "$plugin_path"/*.plugin.zsh; do
source "$p"
done
done
custom_plugins=(
# try zoxide instead
# '/usr/share/z/z.sh'
# use atuin instead
# '/usr/share/fzf/key-bindings.zsh'
'/usr/share/fzf/completion.zsh'
'/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh'
'/usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh'
'/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh'
'/usr/share/doc/pkgfile/command-not-found.zsh'
)
for plugin in $custom_plugins; do
[[ -r "$plugin" ]] && source "$plugin"
done
# }
# plugin settings {
# zsh-syntax-highlighting {
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
# better visibility
ZSH_HIGHLIGHT_PATTERNS+=('\|' fg=cyan,bold)
# potentially dangerous
ZSH_HIGHLIGHT_PATTERNS+=('rm -(r|f)## *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('sudo *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('curl * \| (b|a)#sh *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('git push (-f|--force)# *' 'fg=white,bold,bg=red')
# makes comments visible
ZSH_HIGHLIGHT_STYLES[comment]='none'
# }
# zsh-autosuggestions {
ZSH_AUTOSUGGEST_USE_ASYNC=1
# }
# }
# map autocompletions {
# needs to be at the end
compdef config=git
compdef scripts=git
compdef mosh=ssh
compdef k=kubectl
# }
# starship {
eval "$(starship init zsh)"
# }
# zsh profiler {
# enable if slow start
# zmodload zsh/zprof
# }