-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zshrc.tmpl
285 lines (245 loc) · 11.7 KB
/
dot_zshrc.tmpl
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
# Common folders
export ZDOTDIR="$HOME"
export DOTFILES="${ZDOTDIR:-$HOME}/.config/dotfiles"
[[ -d "$DOTFILES" ]] || mkdir -p "$DOTFILES"
export ZSH_DOTFILES="$DOTFILES/zsh"
[[ -d "$ZSH_DOTFILES" ]] || mkdir -p "$ZSH_DOTFILES"
export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}"
[[ -d "$ZSH_CACHE_DIR" ]] || mkdir -p "$ZSH_CACHE_DIR"
# https://gnunn1.github.io/tilix-web/manual/vteconfig/
#if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
# source /etc/profile.d/vte.sh
#fi
eval "$(oh-my-posh init zsh --config $HOME/.config/ohmyposh/powerlevel10k_rainbow.omp.json)"
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
zdharma-continuum/zinit-annex-as-monitor \
zdharma-continuum/zinit-annex-bin-gem-node \
zdharma-continuum/zinit-annex-patch-dl \
zdharma-continuum/zinit-annex-rust
### End of Zinit's installer chunk
# ZSH Settings
autoload -Uz compinit; compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"
autoload -U +X bashcompinit && bashcompinit
autoload -U colors && colors # Load Colors.
unsetopt case_glob # Use Case-Insensitve Globbing.
setopt globdots # Glob Dotfiles As Well.
setopt extendedglob # Use Extended Globbing.
setopt autocd # Automatically Change Directory If A Directory Is Entered.
# Smart URLs.
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
# General.
setopt brace_ccl # Allow Brace Character Class List Expansion.
setopt combining_chars # Combine Zero-Length Punctuation Characters ( Accents ) With The Base Character.
setopt rc_quotes # Allow 'Henry''s Garage' instead of 'Henry'\''s Garage'.
unsetopt mail_warning # Don't Print A Warning Message If A Mail File Has Been Accessed.
# Jobs.
setopt long_list_jobs # List Jobs In The Long Format By Default.
setopt auto_resume # Attempt To Resume Existing Job Before Creating A New Process.
setopt notify # Report Status Of Background Jobs Immediately.
unsetopt bg_nice # Don't Run All Background Jobs At A Lower Priority.
unsetopt hup # Don't Kill Jobs On Shell Exit.
unsetopt check_jobs # Don't Report On Jobs When Shell Exit.
setopt correct # Turn On Corrections
# Completion Options.
setopt complete_in_word # Complete From Both Ends Of A Word.
setopt always_to_end # Move Cursor To The End Of A Completed Word.
setopt path_dirs # Perform Path Search Even On Command Names With Slashes.
setopt auto_menu # Show Completion Menu On A Successive Tab Press.
setopt auto_list # Automatically List Choices On Ambiguous Completion.
setopt auto_param_slash # If Completed Parameter Is A Directory, Add A Trailing Slash.
setopt no_complete_aliases
setopt menu_complete # Do Not Autoselect The First Completion Entry.
unsetopt flow_control # Disable Start/Stop Characters In Shell Editor.
# define the completer we’ll use for our completion system
# The order matter: the completion system will try each of these completer one after the other
zstyle ':completion:*' completer _expand_alias _expand _complete _correct _approximate
# If you end up using a directory as argument, this will remove the trailing slash (usefull in ln)
zstyle ':completion:*' squeeze-slashes true
# cd will never select the parent directory (e.g.: cd ../<TAB>):
zstyle ':completion:*:cd:*' ignore-parents parent pwd
# Using a cache for the completion can speed up some commands, like apt for example. Let’s add the following in our file to enable it:
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "$ZSH_CACHE_DIR/.zcompcache"
# To group the different type of matches under their descriptions,
zstyle ':completion:*' group-name ''
zstyle ':completion:*:*:-command-:*:*' group-order aliases builtins functions commands
zstyle ':completion:*:*:-command-:*:*' group-order alias builtins functions commands
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' menu select=2
zstyle ':completion:*:*:*:*:corrections' format '%F{yellow}!- %d (errors: %e) -!%f'
zstyle ':completion:*:*:*:*:descriptions' format '%F{blue}-- %D %d --%f'
zstyle ':completion:*:*:*:*:messages' format ' %F{purple} -- %d --%f'
zstyle ':completion:*:*:*:*:warnings' format ' %F{red}-- no matches found --%f'
# zstyle ':completion:*:default' list-prompt '%S%M matches%s'
# Colors for files and directory
zstyle ':completion:*:*:*:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
# Completing process IDs with menu selection:
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
# See ZSHCOMPWID "completion matching control"
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' keep-prefix true
zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'
zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'ls --color $realpath'
# History
export HISTFILE="$XDG_STATE_HOME"/zsh/history
export MCFLY_HISTFILE="$XDG_STATE_HOME"/zsh/history
HISTSIZE=60000
SAVEHIST=60000
setopt bang_hist # Treat The '!' Character Specially During Expansion.
setopt prompt_subst # append history list to the history file; this is the default but we make sure, because it's required for share_history.
setopt inc_append_history # Write To The History File Immediately, Not When The Shell Exits.
setopt share_history # Share History Between All Sessions.
setopt hist_expire_dups_first # Expire A Duplicate Event First When Trimming History.
setopt hist_ignore_dups # Do Not Record An Event That Was Just Recorded Again.
setopt hist_ignore_all_dups # Delete An Old Recorded Event If A New Event Is A Duplicate.
setopt hist_find_no_dups # Do Not Display A Previously Found Event.
setopt hist_ignore_space # Do Not Record An Event Starting With A Space.
setopt hist_save_no_dups # Do Not Write A Duplicate Event To The History File.
setopt hist_verify # Do Not Execute Immediately Upon History Expansion.
setopt extended_history # Show Timestamp In History
setopt interactivecomments # enable interactivecomments
stty -ixon # Disable flowcontrol
bindkey -e
# Functions and stuff
zinit ice from"gitlab"
zinit light papanito/shell-helper-library
# Load aliases, functions, etc.
[[ -d $DOTFILES ]] && for f ($DOTFILES/*.sh) source $f
[[ -d $ZSH_DOTFILES ]] && for f ($ZSH_DOTFILES/*(N.)) source $f
export ZSHRC_LOCAL=$DOTFILES/zsh/zshrc.local
# settings that vary per workstation
[[ -f $ZSHRC_LOCAL ]] && source $ZSHRC_LOCAL
## Ensure completions directory exists
if [[ ! -d $ZSH_CACHE_DIR/completions/ ]]; then
mkdir "$ZSH_CACHE_DIR/completions/"
fi
{{ if eq .chezmoi.hostname "clawfinger" }}
autoload -U add-zsh-hook # Load the zsh hook module
add-zsh-hook preexec pre_validation # Adds the hook
{{ end }}
## https://z.digitalclouds.dev/docs/getting_started/overview/
zinit snippet OMZ::plugins/aliases
zinit snippet OMZ::plugins/alias-finder
zstyle ':omz:plugins:alias-finder' autoload yes # disabled by default
zstyle ':omz:plugins:alias-finder' longer false # disabled by default
zstyle ':omz:plugins:alias-finder' exact yes # disabled by default
zstyle ':omz:plugins:alias-finder' cheaper yes # disabled by default
#zinit snippet OMZ::plugins/tmux
{{ if .isDeveloperMachine }}
zinit snippet OMZ::plugins/ansible
# zinit snippet OMZ::plugins/docker
# zinit snippet OMZ::plugins/docker-compose
zinit snippet OMZ::plugins/colorize
zinit snippet OMZ::plugins/dotenv
zinit snippet OMZ::plugins/fzf
zinit snippet OMZ::plugins/flutter
zinit snippet OMZ::plugins/gnu-utils
zinit snippet OMZ::plugins/gcloud
zinit snippet OMZ::plugins/git
zinit snippet OMZ::plugins/git-extras
zinit snippet OMZ::plugins/gh
zinit snippet OMZ::plugins/github
zinit snippet OMZ::plugins/gitignore
zinit snippet OMZ::plugins/git-prompt
zinit snippet OMZ::plugins/golang
zinit snippet OMZ::plugins/helm
zinit snippet OMZ::plugins/kubectl
zinit snippet OMZ::plugins/podman
zinit ice silent
zinit snippet OMZ::plugins/gradle
zinit snippet OMZ::plugins/pip
zinit snippet OMZ::plugins/pipenv
zinit snippet OMZ::plugins/pyenv
zinit snippet OMZ::plugins/pylint
zinit snippet OMZ::plugins/python
zinit snippet OMZ::plugins/ssh-agent
zinit snippet OMZ::plugins/skaffold
zinit snippet OMZ::plugins/systemd
zinit snippet OMZ::plugins/rsync
zinit snippet OMZ::plugins/thefuck
zinit snippet OMZ::plugins/terraform
{{- end }}
{{- if .isDeveloperMachine }}
# use exa instead ls
export exa_params=('--git' '--classify' '--group-directories-first' '--time-style=long-iso' '--group' '--color-scale')
zinit load zplugin/zsh-exa
{{- end }}
# install zoxide
zinit ice as'null' from"gh-r" sbin
zinit load ajeetdsouza/zoxide
zinit snippet OMZ::plugins/zoxide
#zinit ice has'zoxide'
#zinit load zdharma-continuum/zsh-zoxide
#zinit ice src"init.sh"
#zinit load b4b4r07/enhancd
# non ohmyzsh plugins
zinit light zsh-users/zsh-history-substring-search # https://github.com/zsh-users/zsh-history-substring-search
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "${keys[Up]}" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
bindkey "${keys[Down]}" history-substring-search-down
{{- if .isDeveloperMachine }}
zinit light-mode for \
zdharma-continuum/z-a-meta-plugins @annexes @zsh-users+fast \
zdharma-continuum/zsh-navigation-tools \
Aloxaf/fzf-tab \
wfxr/forgit \
papanito/bwf \
mbhynes/fzf-gcloud \
reegnz/jq-zsh-plugin \
gko/ssh-connect
# completion stuff
AZCOMP=/etc/bash_completion.d/azure-cli
[[ ! -f $AZCOMP ]] || source $AZCOMP
AZCOMP2=$DOTFILES/az.completion
[[ -f $AZCOMP2 ]] && source $AZCOMP2
GCLOUDCOMP=$GOOGLE_CLOUD_SDK_HOME/completion.zsh.inc
[[ -f $GCLOUDCOMP ]] && source $GCLOUDCOMP
{{- else }}
zinit light-mode for \
z-shell/z-a-meta-plugins @annexes @zsh-users+fast \
z-shell/zsh-navigation-tools \
Aloxaf/fzf-tab
{{- end }}
# widgets
zle -N znt-cd-widget
bindkey "^B" znt-cd-widget
zle -N znt-kill-widget
bindkey "^Y" znt-kill-widget
{{- if .isDeveloperMachine }}
## helper tools
which direnv &>/dev/null && eval "$(direnv hook zsh)"
which navi &>/dev/null && eval "$(navi widget zsh)"
which hcloud &>/dev/null && eval "$(hcloud completion zsh)"
which podman &>/dev/null && eval "$(podman completion zsh)"
which kind &>/dev/null && eval "$(kind completion zsh)"
which fzf &>/dev/null && eval "$(fzf --zsh)"
eval "$(zoxide init --cmd cd zsh)"
## Hishtory
which hishtory &>/dev/null && \
source $HISHTORY/config.zsh && \
eval "$(hishtory completion zsh)" && \
hishtory enable && \
hishtory config-set filter-duplicate-commands true
{{- end }}
{{- if eq .osid "linux-nixos" }}
export NIX_HM_SESSION_VARS="$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
[[ -f "$NIX_HM_SESSION_VARS" ]] && source "$NIX_HM_SESSION_VARS"
{{- end }}