Mercurial > dotfiles
annotate dot_zshrc @ 536:87f5a409ee83
Add zsh syntax highlighting in shell
author | zegervdv <zegervdv@me.com> |
---|---|
date | Thu, 27 Jan 2022 09:27:53 +0100 |
parents | f10b89e9aff3 |
children | 0cc89a031281 |
rev | line source |
---|---|
261 | 1 # vim:ft=zsh |
2 | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
3 source ~/.zsh/zsh-history-substring-search.zsh |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
4 export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=green,fg=black' |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
5 |
531 | 6 source ~/.zsh/zsh-autosuggestions.zsh |
7 | |
536
87f5a409ee83
Add zsh syntax highlighting in shell
zegervdv <zegervdv@me.com>
parents:
535
diff
changeset
|
8 source ~/.zsh/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh |
87f5a409ee83
Add zsh syntax highlighting in shell
zegervdv <zegervdv@me.com>
parents:
535
diff
changeset
|
9 |
534
aee830df7a88
Add zsh completions for fd and rg
zegervdv <zegervdv@me.com>
parents:
533
diff
changeset
|
10 fpath=(~/.zsh/completions $fpath) |
aee830df7a88
Add zsh completions for fd and rg
zegervdv <zegervdv@me.com>
parents:
533
diff
changeset
|
11 |
293
b29fc37fe1f0
Set TERM to xterm-256color
Zeger Van de Vannet <zegervdv@me.com>
parents:
289
diff
changeset
|
12 export TERM=xterm-256color |
b29fc37fe1f0
Set TERM to xterm-256color
Zeger Van de Vannet <zegervdv@me.com>
parents:
289
diff
changeset
|
13 |
261 | 14 export LC_ALL=$LANG |
15 | |
16 PROMPT='%F{cyan}%T%f %F{red}%m%f %F{blue}%~%b%f | |
265 | 17 %j -> ' |
261 | 18 |
19 | |
265 | 20 vim_ins_mode="%F{black}%K{yellow} INS %k%f" |
266
7a275f0d38e8
Use red to indicate Normal mode in zsh prompt
zegervdv <zegervdv@me.com>
parents:
265
diff
changeset
|
21 vim_cmd_mode="%F{white}%K{red} NRM %k%f" |
261 | 22 vim_mode=$vim_ins_mode |
23 | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
24 # Cursor mapping from nyquase/vi-mode |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
25 function select_cursor() { |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
26 case $KEYMAP in |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
27 # Block cursor in normal and visual mode |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
28 vicmd) echo -ne "\e[2 q";; |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
29 # Line cursor in insert mode |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
30 main|viins) echo -ne "\e[5 q";; |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
31 # Else Block cursor |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
32 *) echo -ne "\e[2 q";; |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
33 esac |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
34 } |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
35 |
261 | 36 function zle-keymap-select { |
37 vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}" | |
38 zle reset-prompt | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
39 zle -R |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
40 select_cursor |
261 | 41 } |
42 zle -N zle-keymap-select | |
43 | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
44 function zle-line-init() { |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
45 echoti smkx |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
46 zle reset-prompt |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
47 select_cursor |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
48 } |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
49 zle -N zle-line-init |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
50 |
261 | 51 function zle-line-finish { |
52 vim_mode=$vim_ins_mode | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
53 echoti rmkx |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
54 echo -ne "\e[2 q" |
261 | 55 } |
56 zle -N zle-line-finish | |
57 | |
58 function TRAPINT() { | |
59 vim_mode=$vim_ins_mode | |
60 return $(( 128 + $1 )) | |
61 } | |
62 | |
535
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
63 autoload -Uz vcs_info |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
64 zstyle ':vcs_info:*' enable git hg |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
65 |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
66 zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
67 zstyle ':vcs_info:*' formats '%F{4}%s%F{5}%F{3} @ %F{2}%b%f' |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
68 zstyle ':vcs_info:hg*:*' use-simple true |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
69 |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
70 precmd () { vcs_info } |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
71 |
f10b89e9aff3
Add git/hg info to zsh prompt
Zeger Van de Vannet <zegervdv@me.com>
parents:
534
diff
changeset
|
72 RPROMPT='${vcs_info_msg_0_} ${vim_mode}' |
261 | 73 |
74 zmodload -i zsh/complist | |
75 | |
76 bindkey -v | |
77 | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
78 bindkey '^[[A' history-substring-search-up |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
79 bindkey '^[[B' history-substring-search-down |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
80 bindkey "$terminfo[kcuu1]" history-substring-search-up |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
81 bindkey "$terminfo[kcud1]" history-substring-search-down |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
82 bindkey '^p' history-substring-search-up |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
83 bindkey '^n' history-substring-search-down |
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
84 |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
85 bindkey '^f' autosuggest-accept |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
86 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
87 zmodload zsh/complist |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
88 bindkey -M menuselect 'h' vi-backward-char |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
89 bindkey -M menuselect 'k' vi-up-line-or-history |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
90 bindkey -M menuselect 'j' vi-down-line-or-history |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
91 bindkey -M menuselect 'l' vi-forward-char |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
92 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
93 # Enter interactive search |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
94 bindkey -M menuselect '^xi' vi-insert |
531 | 95 |
263 | 96 export LESS_TERMCAP_mb=$(printf "\e[1;31m") |
97 export LESS_TERMCAP_md=$(printf "\e[1;31m") | |
98 export LESS_TERMCAP_me=$(printf "\e[0m") | |
99 export LESS_TERMCAP_se=$(printf "\e[0m") | |
100 export LESS_TERMCAP_so=$(printf "\e[1;44;33m") | |
101 export LESS_TERMCAP_ue=$(printf "\e[0m") | |
102 export LESS_TERMCAP_us=$(printf "\e[1;32m") | |
262
44d179225271
Add history substring search plugin
zegervdv <zegervdv@me.com>
parents:
261
diff
changeset
|
103 |
261 | 104 export CLICOLOR=1 |
105 export LS_COLORS='no=00;37:fi=00:di=00;33:ln=04;36:pi=40;33:so=01;35:bd=40;33;01:' | |
106 | |
107 # Options | |
108 setopt monitor | |
109 setopt auto_cd | |
110 setopt cdablevars | |
111 setopt pushd_ignore_dups | |
112 setopt interactive_comments | |
113 setopt append_history | |
114 setopt inc_append_history | |
115 setopt hist_ignore_dups | |
116 setopt hist_find_no_dups | |
117 setopt hist_reduce_blanks | |
118 setopt extended_history | |
119 setopt hist_expire_dups_first | |
120 setopt hist_verify | |
121 setopt share_history | |
122 setopt transient_rprompt | |
123 setopt prompt_subst | |
124 setopt multios | |
125 setopt correct_all | |
126 setopt autopushd | |
127 setopt pushdminus | |
128 setopt pushdsilent | |
129 setopt nobeep | |
130 setopt notify | |
131 REPORTTIME=5 | |
132 | |
133 HISTSIZE=3000 | |
134 SAVEHIST=3000 | |
135 HISTFILE=~/.zsh_history | |
136 | |
137 # Completion | |
138 setopt complete_in_word | |
139 setopt always_to_end | |
140 setopt auto_menu | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
141 setopt auto_param_slash |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
142 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
143 # Enable completers |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
144 zstyle ':completion:*' completer _complete _approximate |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
145 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
146 zstyle ':completion:*' use-cache on |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
147 zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache" |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
148 |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
149 # file list info |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
150 zstyle ':completion:*' file-list list |
261 | 151 |
152 # activate color-completion | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
153 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} |
261 | 154 |
155 # format on completion | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
156 zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' |
261 | 157 |
158 # insert all expansions for expand completer | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
159 zstyle ':completion:*:expand:*' tag-order all-expansions |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
160 zstyle ':completion:*:history-words' list false |
261 | 161 |
162 # activate menu | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
163 zstyle ':completion:*:history-words' menu yes |
261 | 164 |
165 # ignore duplicate entries | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
166 zstyle ':completion:*:history-words' remove-all-dups yes |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
167 zstyle ':completion:*:history-words' stop yes |
261 | 168 |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
169 zstyle ':completion:*:matches' group 'yes' |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
170 zstyle ':completion:*' group-name '' |
261 | 171 if [[ "$NOMENU" -eq 0 ]] ; then |
172 # if there are more than 5 options allow selecting from a menu | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
173 zstyle ':completion:*' menu select=5 |
261 | 174 else |
175 # don't use any menus at all | |
176 setopt no_auto_menu | |
177 fi | |
178 | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
179 zstyle ':completion:*:messages' format '%d' |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
180 zstyle ':completion:*:options' auto-description '%d' |
261 | 181 |
182 # describe options in full | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
183 zstyle ':completion:*:options' description 'yes' |
261 | 184 |
185 # complete manual by their section | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
186 zstyle ':completion:*:manuals' separate-sections true |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
187 zstyle ':completion:*:manuals.*' insert-sections true |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
188 zstyle ':completion:*:man:*' menu yes select |
261 | 189 |
190 # Search path for sudo completion | |
191 zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \ | |
192 /usr/local/bin \ | |
193 /usr/sbin \ | |
194 /usr/bin \ | |
195 /sbin \ | |
196 /bin \ | |
197 /usr/X11R6/bin | |
198 | |
199 # provide .. as a completion | |
200 zstyle ':completion:*' specal-dirs .. | |
201 | |
202 # case insensitive path-completion | |
203 zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' | |
204 | |
205 # nvim completion | |
533
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
206 zstyle ':completion:*:*:nvim:*' ignored-patterns '*.(o|hex|elf|pyc|pdf|dup)' |
22fb4745cb1b
set more completion options in zsh
Zeger Van de Vannet <zegervdv@me.com>
parents:
531
diff
changeset
|
207 zstyle ':completion:*:*:nvim:*' file-sort modification |
261 | 208 |
209 autoload -U compinit && compinit | |
210 | |
211 # fg when pressing Ctrl+Z | |
212 function fancy-ctrl-z () { | |
213 if [[ $#BUFFER -eq 0 ]]; then | |
214 if [[ $(jobs | wc -l) -gt 0 ]]; then | |
215 BUFFER='fg' | |
216 zle accept-line | |
217 fi | |
218 else | |
219 zle push-input | |
220 zle clear-screen | |
221 fi | |
222 } | |
223 zle -N fancy-ctrl-z | |
224 bindkey '^Z' fancy-ctrl-z | |
225 | |
226 # Aliases | |
479 | 227 alias l="ls -haltr" |
228 alias ll="ls -haltr" | |
261 | 229 alias xclip='xclip -selection clipboard' |
269 | 230 alias view='nvim -R' |
261 | 231 |
232 # Exports | |
233 export XDG_CONFIG_HOME=$HOME/.config | |
234 export PATH=$HOME/bin:$PATH | |
235 | |
236 export EDITOR=nvim | |
237 export HGEDITOR=nvim | |
238 | |
504 | 239 export RIPGREP_CONFIG_PATH=$HOME/.config/ripgrep/ripgreprc |
506 | 240 export BAT_CONFIG_PATH=$HOME/.config/bat/config |
504 | 241 |
267 | 242 [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh |
261 | 243 export FZF_DEFAULT_COMMAND='ag -g ""' |
267 | 244 [ -f ~/.zshrc.local ] && source ~/.zshrc.local |
491
f1d1eab204aa
Fix paths to nvim for SUDO_EDITOR
zegervdv <zegervdv@me.com>
parents:
490
diff
changeset
|
245 |
f1d1eab204aa
Fix paths to nvim for SUDO_EDITOR
zegervdv <zegervdv@me.com>
parents:
490
diff
changeset
|
246 # Must run after brew is loaded |
f1d1eab204aa
Fix paths to nvim for SUDO_EDITOR
zegervdv <zegervdv@me.com>
parents:
490
diff
changeset
|
247 export SUDO_EDITOR=$(which nvim) |
508 | 248 eval "$(direnv hook zsh)" |