-
Notifications
You must be signed in to change notification settings - Fork 2
/
6-zsh_options.rc
271 lines (198 loc) · 7.84 KB
/
6-zsh_options.rc
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
# shellcheck disable=SC2148 disable=SC1090 shell=bash
### Options ###
#unalias run-help
# autoload run-help
# HELPDIR=/usr/local/share/zsh/help
# Useful for moving / renaming files with glob patterns
# e.g. zmv -W '**/*.js' '**/*.ts' # recursively move anything matching the first pattern to the second pattern
autoload -Uz zmv
zmodload zsh/complist
zmodload zsh/mapfile # bring mapfile to zsh
# zmodload zsh/attr # attrs info
# Keep echo "station" > station from clobbering station
setopt NO_CLOBBER
# Case insensitive globbing
setopt NO_CASE_GLOB
# Be Reasonable!
setopt NUMERIC_GLOB_SORT
# I don't know why I never set this before.
setopt EXTENDED_GLOB
### Completion Stuff ###
## zsh-completion-generator ##
# Requires zgen load RobSis/zsh-completion-generator - see 1-zgen.rc
# Can also be run on the cli using: gencomp <command>
zstyle :plugin:zsh-completion-generator programs ggrep tr cat xattr
##
# If we have a glob this will expand it
setopt GLOB_COMPLETE
setopt PUSHD_MINUS
bindkey -M viins '\C-i' complete-word
zstyle ':zle:*-word-shell' word-style shell
zle -N forward-word-shell forward-word-match
zle -N backward-word-shell backward-word-match
# Faster! (?)
zstyle ':completion::complete:*' use-cache 1
# case insensitive completion
# NOTE THIS MAY CAUSE PERFORMANCE ISSUES
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# tab completion for the middle of words
autoload compinstall
zstyle ':completion:*' matcher-list '' '' '' 'l:|=* r:|=*'
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*' group-name ''
# AWS specific
zstyle ':completion:*:*:aws' fzf-search-display true
# Note these need functions to be defined, see functions.rc
zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete
zstyle ':completion:*' completer _expand _force_rehash _complete _ignored
zstyle ':completion:*:*:docker:*' option-stacking yes
zstyle ':completion:*:*:docker-*:*' option-stacking yes
# Group completions by type (file, external command, etc)
zstyle ':completion:*:matches' group 'yes'
# don't mess up url passing as arguments
zstyle ':urlglobber' url-other-schema
# generate descriptions with magic.
zstyle ':completion:*' auto-description 'specify: %d'
# Don't prompt for a huge list, page it!
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
# Don't prompt for a huge list, menu it!
zstyle ':completion:*:default' menu 'select=0'
# Have the newer files last so I see them first
zstyle ':completion:*' file-sort modification reverse
# color code completion!!!! Wohoo!
zstyle ':completion:*' list-colors "=(#b) #([0-9]#)*=36=31"
# don't tab complete hosts (slow and if you have ad-blocking in your hosts file annoying)
#zstyle ':completion:*' hosts off
unsetopt LIST_AMBIGUOUS
setopt COMPLETE_IN_WORD
# Separate man page sections. Neat.
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*' list-separator '»»'
# complete with a menu for xwindow ids
zstyle ':completion:*:windows' menu on=0
zstyle ':completion:*:expand:*' tag-order all-expansions
# more errors allowed for large words and fewer for small words
zstyle ':completion:*:approximate:*' max-errors "reply=( $((($#PREFIX + $#SUFFIX) / 3)) )"
# Errors format
zstyle ':completion:*:corrections' format '%B%d (errors %e)%b'
zstyle ':completion:*:correct:*' insert-unambiguous true
zstyle ':completion:*:correct:*' original true
# Don't complete stuff already on the line
zstyle ':completion::*:(rm|vi):*' ignore-line true
# Don't complete directory we are already in (../here)
zstyle ':completion:*' ignore-parents parent pwd
zstyle ':completion::approximate*:*' prefix-needed false
# make kill way awesome
zstyle ':completion:*:processes' command 'ps -au$USER -o pid,time,cmd|grep -v "ps -au$USER -o pid,time,cmd"'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)[ 0-9:]#([^ ]#)*=01;30=01;31=01;38'
### Auto Suggest Settings ###
# Autosuggest highlight colour
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#7c4fef,bold,underline"
# Autosuggestions from history, if none use the completion engine.
export ZSH_AUTOSUGGEST_STRATEGY=(history completion)
# Accept autosuggestion with shift+tab - I use this EVERY day
bindkey '^I' complete-word # tab | complete
bindkey '^[[Z' autosuggest-accept # shift + tab | autosuggest
# Autocomplete kubectl for k alias
# complete -F __start_kubectl k
# compdef __start_kubectl k
### END Autocompletion ###
### Key bindings ###
# Who doesn't want home and end to work?
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
# Incremental search is elite!
bindkey -M vicmd "/" history-incremental-search-backward
bindkey -M vicmd "?" history-incremental-search-forward
# Search based on what you typed in already
bindkey -M vicmd "//" history-beginning-search-backward
bindkey -M vicmd "??" history-beginning-search-forward
# oh wow! This is killer... try it!
bindkey -M vicmd "q" push-line
# Ensure that arrow keys work as they should
bindkey '\e[A' up-line-or-history
bindkey '\e[B' down-line-or-history
bindkey '\eOA' up-line-or-history
bindkey '\eOB' down-line-or-history
bindkey '\e[C' forward-char
bindkey '\e[D' backward-char
bindkey '\eOC' forward-char
bindkey '\eOD' backward-char
# bindkey "5C" emacs-forward-word
# bindkey "5D" backward-word
bindkey "5C" forward-word #control left
bindkey "5D" backward-word #control right
bindkey "^[[1;5C" forward-word #control left in xterm/tmux
bindkey "^[[1;5D" backward-word #control right in xterm/tmux
bindkey "^[[A" history-search-backward # Search history with up arrow
bindkey "^[[B" history-search-forward # Search history with up arrow
# gross. Makes Meta-' write '\'' for you
bindkey -s \\e\' \'\\\\\'\'
# bindkey "^[[3~" delete-char # delete keys
# bindkey "^[3;5~" delete-char # delete keys
bindkey -M emacs '^H' backward-kill-word # backwards delete word
# it's like, space AND completion. Gnarlbot.
bindkey -M viins ' ' magic-space
# Push your line to the stack and run another command then pop it back
bindkey -M vicmd "^q" push-line
# cd into a directory when you type its name
setopt autocd
### Fix slowness of pastes with zsh-syntax-highlighting.zsh ###
# Still needed as of 2023-06-24!
pasteinit() {
# shellcheck disable=SC2296,SC2298
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic
}
pastefinish() {
zle -N self-insert "$OLD_SELF_INSERT"
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
### End fix slowness of pastes ###
# Suggest corrections for commands
setopt correct
# ### Expand aliases
# globalias() {
# zle _expand_alias
# zle expand-word
# zle self-insert
# }
# zle -N globalias
# # space expands all aliases, including global
# bindkey -M emacs " " globalias
# bindkey -M viins " " globalias
# # control-space to make a normal space
# bindkey -M emacs "^ " magic-space
# bindkey -M viins "^ " magic-space
# # normal space during searches
# bindkey -M isearch " " magic-space
#nav bindkeys
# bindkey '^[[1;5A' nav-up # cmd + up
# bindkey '^[[1;5B' nav-down # cmd + down
# bindkey '^[[1;5C' nav-forward # cmd + right
# bindkey '^[[1;5D' nav-back # cmd + left
# #
# Bind ctrl+g to run the command 'git status'
_git_status() {
git status
zle redisplay
}
zle -N _git_status
bindkey '^g' '_git_status' # ctrl + g
# Bind ctrl+l to run sgpt with all text on the command line as a single quoted argument
_sgptline() {
LINE=$LBUFFER
echo -e "\n"
sgpt "'$LINE'"
LBUFFER=""
zle redisplay
}
zle -N _sgptline
bindkey '^l' '_sgptline' # ctrl + l
# https://github.com/ohmyzsh/ohmyzsh/wiki/Settings
# Oh My Zsh will print a red ellipsis to indicate that Zsh is still processing a completion request
export COMPLETION_WAITING_DOTS=true