generated from anishathalye/dotfiles_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
330 lines (282 loc) · 12.2 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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!usr/bin/env zsh
# - - - - - - - - - - - - - - - - - - - -
# Profiling Tools
# - - - - - - - - - - - - - - - - - - - -
PROFILE_STARTUP=false
if [[ "$PROFILE_STARTUP" == true ]]; then
zmodload zsh/zprof
# http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html
PS4=$'%D{%M%S%.} %N:%i> '
exec 3>&2 2>$HOME/startlog.$$
setopt xtrace prompt_subst
fi
# - - - - - - - - - - - - - - - - - - - -
# Zsh Core Configuration
# - - - - - - - - - - - - - - - - - - - -
export XDG_CONFIG_HOME="$HOME/.config"
export CACHEDIR="$HOME/.local/share"
[[ -d "$CACHEDIR" ]] || mkdir -p "$CACHEDIR"
# Load The Prompt System And Completion System And Initilize Them.
autoload -Uz compinit promptinit
# Load And Initialize The Completion System Ignoring Insecure Directories With A
# Cache Time Of 20 Hours, So It Should Almost Always Regenerate The First Time A
# Shell Is Opened Each Day.
# See: https://gist.github.com/ctechols/ca1035271ad134841284
_comp_files=(${ZDOTDIR:-$HOME}/.zcompdump(Nm-20))
if (( $#_comp_files )); then
compinit -i -C
else
compinit -i
fi
unset _comp_files
promptinit
setopt prompt_subst
# - - - - - - - - - - - - - - - - - - - -
# ZSH Settings
# - - - - - - - - - - - - - - - - - - - -
autoload -U colors && colors # Load Colors.
unsetopt case_glob # Use Case-Insensitve Globbing.
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 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.
# Zstyle.
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f'
zstyle ':completion:*:descriptions' format ' %F{yellow}-- %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'
zstyle ':completion:*' format ' %F{yellow}-- %d --%f'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' verbose yes
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path "$HOME/.zcompcache"
zstyle ':completion:*' list-colors $LS_COLORS
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'
zstyle ':completion:*' rehash true
# History.
HISTFILE="${ZDOTDIR:-$HOME}/.zsh_history"
HISTSIZE=100000
SAVEHIST=5000
setopt appendhistory notify
unsetopt beep nomatch
setopt bang_hist # Treat The '!' Character Specially During Expansion.
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.
# - - - - - - - - - - - - - - - - - - - -
# Zinit Configuration
# - - - - - - - - - - - - - - - - - - - -
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
print -P "%F{33} %F{34}Installation successful.%f%b" || \
print -P "%F{160} The clone has failed.%f%b"
fi
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# Create cache directory for completions (ZSH_CACHE_DIR is defined by zinit)
[[ -d "$ZSH_CACHE_DIR/completions" ]] || mkdir -p "$ZSH_CACHE_DIR/completions"
# - - - - - - - - - - - - - - - - - - - -
# Theme
# - - - - - - - - - - - - - - - - - - - -
# Most Themes Use This Option.
setopt promptsubst
# Provide A Simple Prompt Till The Theme Loads
PS1="READY >"
# Load starship
zinit ice from"gh-r" as"command" atload'eval "$(starship init zsh)"'
zinit load starship/starship
# - - - - - - - - - - - - - - - - - - - -
# Annexes
# - - - - - - - - - - - - - - - - - - - -
# 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 \
NICHOLAS85/z-a-linkman \
NICHOLAS85/z-a-linkbin
# - - - - - - - - - - - - - - - - - - - -
# Plugins
# - - - - - - - - - - - - - - - - - - - -
# Load these plugins ASAP without Turbo. Explanation:
# - History plugin is loaded early (as it has some defaults) to prevent empty history stack for other plugins
zinit lucid for \
atinit"HIST_STAMPS=dd.mm.yyyy" \
OMZL::history.zsh \
# Trigger-load block
zinit wait depth'3' lucid light-mode for \
trigger-load'!x' \
OMZ::plugins/extract \
trigger-load'!man' \
ael-code/zsh-colored-man-pages \
trigger-load'!z' \
agkozak/zsh-z
# Load OMZ plugins in Turbo mode
zinit wait lucid for \
OMZL::clipboard.zsh \
OMZL::compfix.zsh \
OMZL::completion.zsh \
OMZL::correction.zsh \
OMZL::directories.zsh \
OMZL::functions.zsh \
OMZL::git.zsh \
OMZL::grep.zsh \
OMZL::key-bindings.zsh \
OMZL::misc.zsh \
OMZL::spectrum.zsh \
OMZL::termsupport.zsh \
OMZP::command-not-found \
OMZP::debian \
OMZP::docker \
OMZP::dirhistory \
OMZP::git \
OMZP::git-extras \
OMZP::rust \
OMZP::ssh-agent \
OMZP::sudo \
djui/alias-tips
# Load important plugins
zinit wait lucid light-mode for \
zdharma-continuum/history-search-multi-word \
atinit"ZINIT[COMPINIT_OPTS]='-i' zpcompinit; zpcdreplay" \
zdharma-continuum/fast-syntax-highlighting \
atload"_zsh_autosuggest_start" \
zsh-users/zsh-autosuggestions \
blockf atpull'zinit creinstall -q .' \
zsh-users/zsh-completions
# - - - - - - - - - - - - - - - - - - - -
# FZF
# - - - - - - - - - - - - - - - - - - - -
# Taken from https://github.com/zdharma-continuum/zinit-configs/blob/master/vladdoster/.zshrc#L81
zinit wait'0b' lucid from"gh-r" as"program" for @junegunn/fzf
# zinit ice wait'0a' lucid; zi snippet https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh
zinit ice wait'1a' lucid; zi snippet https://github.com/junegunn/fzf/blob/master/shell/completion.zsh
# Handy plugins built on top of fzf
zinit wait'2' lucid for \
atinit"forgit_ignore='fgi'" \
wfxr/forgit
# - - - - - - - - - - - - - - - - - - - -
# Binaries
# - - - - - - - - - - - - - - - - - - - -
zinit wait'0c' depth'3' lucid light-mode binary from'gh-r' lman lbin for \
lbin'**/gh' atclone'./**/gh completion --shell zsh > _gh' atpull'%atclone' \
cli/cli \
atclone'./just --completions zsh > _just' atpull'%atclone' \
casey/just \
zinit wait'1a' depth'1' lucid from"gh-r" as'program' for \
pick"delta*/delta" dandavison/delta \
pick'git-sizer' @github/git-sizer \
pick'grex' pemistahl/grex \
pick'lazygit' @jesseduffield/lazygit \
atload'alias lzg="lazygit"' \
pick'lazydocker' @jesseduffield/lazydocker \
atload'alias lzd="lazydocker"' \
pick'shfmt' bpick"${bpick}" @mvdan/sh
zinit wait'1b' depth'1' lucid from'gh-r' as"command" for \
mv'bat* bat' sbin'**/bat -> bat' \
atload'export BAT_THEME="Dracula"
alias cat=bat' \
@sharkdp/bat \
mv'fd* fd' sbin'**/fd -> fd' @sharkdp/fd \
mv'hyperfine* hyperfine' sbin'**/hyperfine -> hyperfine' @sharkdp/hyperfine \
mv'hexyl* hexyl' sbin'**/hexyl -> hexyl' @sharkdp/hexyl \
mv'vivid* vivid' sbin'**/vivid -> vivid' \
atload'export LS_COLORS="$(vivid generate snazzy)"' @sharkdp/vivid \
mv'rip* ripgrep' sbin'**/rg -> rg' \
atclone'cp -vf ripgrep/complete/_rg _rg' atpull"%atclone" \
BurntSushi/ripgrep \
mv'nvim* nvim' sbin"**/bin/nvim -> nvim" bpick"${bpick}" \
atload'export EDITOR="nvim"
alias v="${EDITOR}"
alias vi="${EDITOR}"
alias vim="${EDITOR}"
' \
neovim/neovim \
sbin'**/exa -> exa' atclone'cp -vf completions/exa.zsh _exa' atpull"%atclone" \
atload"alias ls='exa --git --group-directories-first'
alias l='ls -blF'
alias la='ls -abghilmu'
alias ll='ls -al'
alias tree='exa --tree'" \
ogham/exa
# - - - - - - - - - - - - - - - - - - - -
# Git extensions
# - - - - - - - - - - - - - - - - - - - -
zinit as"null" wait"3" lucid for \
sbin Fakerr/git-recall \
sbin paulirish/git-open \
sbin paulirish/git-recent \
sbin davidosomething/git-my \
sbin atload"export _MENU_THEME=legacy" \
arzzen/git-quick-stats \
make"PREFIX=$ZPFX" atclone'cp -vf etc/git-extras-completion.zsh _git-extras' atpull"%atclone" \
tj/git-extras
# - - - - - - - - - - - - - - - - - - - -
# Managers
# - - - - - - - - - - - - - - - - - - - -
# pyenv
zinit ice atclone'PYENV_ROOT="$PWD" ./libexec/pyenv init --path > zpyenv.zsh
PYENV_ROOT="$PWD" ./libexec/pyenv init - >> zpyenv.zsh
' \
atinit'export PYENV_ROOT="$PWD"' atpull"%atclone" \
as'command' pick'bin/pyenv' src"zpyenv.zsh" nocompile'!'
zinit light pyenv/pyenv
# nvm
zinit ice atinit'\
export NVM_SYMLINK_CURRENT="true"
export NVM_DIR="$HOME/.nvm"
export NVM_LAZY_LOAD=true
export NVM_LAZY_LOAD_EXTRA_COMMANDS=("pnpm" "nvim")
export NVM_COMPLETION=true
'
zinit light lukechilds/zsh-nvm
# - - - - - - - - - - - - - - - - - - - -
# End Profiling Script
# - - - - - - - - - - - - - - - - - - - -
if [[ "$PROFILE_STARTUP" == true ]]; then
unsetopt xtrace
exec 2>&3 3>&-
zprof > ~/zshprofile$(date +'%s')
fi