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