-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathzshrc
332 lines (266 loc) · 11.6 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
331
332
#
# Z-Shell Init
#
# In our zshenv file we have on macOS disabled loading ZSH startup files from
# /etc to avoid /etc/zprofile messing up our carefully constructed PATH. So we
# need to manually load the other files we care about.
if [[ "$OSTYPE" == "darwin"* ]] && [ -f "/etc/zshrc" ]; then
source "/etc/zshrc"
fi
# ==============================================================================
# Helper Functions
# ==============================================================================
source "$DOTZSH/zshrc.funcs.zsh"
# ==============================================================================
# Zinit
# ==============================================================================
declare -A ZINIT
ZINIT[HOME_DIR]="$HOME/.local/zsh/zinit"
ZINIT[BIN_DIR]="${ZINIT[HOME_DIR]}/bin"
# Load zinit module if it exists. For more info, run: zinit module help
if [ -f "${ZINIT[HOME_DIR]}/module/Src/zdharma_continuum/zinit.so" ]; then
module_path+=("${ZINIT[HOME_DIR]}/module/Src")
zmodload zdharma_continuum/zinit
fi
# Ask to clone Zinit if it's not already available on disk.
[ ! -d "${ZINIT[BIN_DIR]}" ] &&
read -q "REPLY?Zinit not installed, clone to ${ZINIT[BIN_DIR]}? [y/N]:" &&
echo &&
git clone --depth=1 "https://github.com/zdharma-continuum/zinit.git" "${ZINIT[BIN_DIR]}"
# Load Zinit
source "${ZINIT[BIN_DIR]}/zinit.zsh"
# Add generic cross platform clipcopy and clippaste commands to copy and paste
# from the system clipboard.
zinit for @OMZ::lib/clipboard.zsh
# ==============================================================================
# Environment
# ==============================================================================
# Ensure mise shims directory is in PATH so that installed tools are immediately
# available for use within shell initialization. We activate mise normally right
# at end which replaces the shims in PATH with a shell hook that updates PATH as
# needed.
path_prepend "$MISE_HOME/shims"
# If available, make sure to load direnv shell hook before mise.
if command-exists direnv; then
cached-eval "$(command-path direnv)" direnv hook zsh
fi
# ==============================================================================
# History
# ==============================================================================
# Set various sane defaults for ZSH history management.
zinit for @OMZ::lib/history.zsh
# Map history search to ctrl-p and ctrl-n.
# bindkey '^p' history-beginning-search-backward
# bindkey '^n' history-beginning-search-forward
## History file configuration
HISTFILE="$HOME/.zsh_history"
HISTSIZE=100000
SAVEHIST=50000
## History command configuration
setopt append_history # append history to HISTFILE
setopt extended_history # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_find_no_dups # do not display a duplicate history entry
setopt hist_ignore_dups # ignore duplicated commands history list
setopt hist_ignore_space # ignore commands that start with space
setopt hist_reduce_blanks # remove superfluous blanks before adding to history
setopt hist_verify # show command with history expansion to user before running it
setopt inc_append_history_time # add timestamp to HISTFILE in order of execution
setopt share_history # share command history data
# ==============================================================================
# Completion
# ==============================================================================
if [ -d "$ZSH_COMPLETIONS" ]; then fpath=("$ZSH_COMPLETIONS" $fpath); fi
if [ -d "$DOTZSH_SITEFUNS" ]; then fpath=("$DOTZSH_SITEFUNS" $fpath); fi
if [ -d "$BREW_SITEFUNS" ]; then fpath=("$BREW_SITEFUNS" $fpath); fi
# Enable interactive selection of completions.
zinit for @OMZ::lib/completion.zsh
# Install fzf-tab if fzf is available.
if command-exists fzf; then
# TODO: Switch back to upstream Aloxaf/fzf-tab when this PR is merged:
# - https://github.com/Aloxaf/fzf-tab/pull/445
zinit light-mode wait lucid atclone'git checkout fit-preview' \
for @jimeh/fzf-tab
zstyle ':fzf-tab:sources' config-directory "$DOTZSH/fzf-tab/sources"
zinit light-mode lucid for @Freed-Wu/fzf-tab-source
# Disable some overly aggressive completions from fzf-tab-source.
zstyle -d ':fzf-tab:complete:*' fzf-preview
fi
zinit light-mode wait lucid blockf for @zsh-users/zsh-completions
zinit light-mode wait lucid atload"!_zsh_autosuggest_start" \
for @zsh-users/zsh-autosuggestions
# Map ctrl+x h to show completion context info.
bindkey '^Xh' _complete_help
# Group completions by type under group headings
zstyle ':completion:*' format '%d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '%d'
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-grouped true
zstyle ':autocomplete:*' groups 'always'
# Case-insensitive completion.
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]-_}={[:upper:][:lower:]_-}' 'r:|=*' 'l:|=* r:|=*'
# git
zstyle ':completion:*:*:git:*:branches' group-name 'local branches'
zstyle ':completion:*:*:git:*:remote-branches' group-name 'remote branches'
zstyle ':completion:*:*:git:*:tags' group-name 'tags'
zstyle ':completion:*:git-checkout:*' sort false
# Improve selection of Makefile completions - from:
# https://github.com/zsh-users/zsh-completions/issues/541#issuecomment-384223016
zstyle ':completion:*:make:*:targets' call-command true
autoload -Uz compinit
compinit
# Setup fzf related stuff if it is available.
if command-exists fzf; then
export FZF_DEFAULT_OPTS="
--bind=ctrl-k:kill-line
--bind=ctrl-v:half-page-down
--bind=alt-v:half-page-up
--tabstop=4
--highlight-line"
export FZF_CTRL_T_OPTS="
--tmux 75%
--walker-skip .git,node_modules,.terraform,target
--bind 'ctrl-/:change-preview-window(down|hidden|)'"
# TODO: replace pbcopy with something that's cross-platform.
export FZF_CTRL_R_OPTS="
--tmux 75%
--border=rounded
--preview 'echo {}' --preview-window up:3:hidden:wrap
--bind 'ctrl-/:toggle-preview'
--bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort'"
export FZF_ALT_C_OPTS="
--tmux 75%
--walker-skip .git,node_modules,.terraform,target
--preview 'tree -C {}'"
cached-eval "$(command-path fzf)" fzf --zsh
zstyle ':completion:*' menu no
zstyle ':completion:*' special-dirs true
zstyle ':fzf-tab:*' fzf-bindings \
'ctrl-v:half-page-down' \
'alt-v:half-page-up' \
'ctrl-k:kill-line'
zstyle ':fzf-tab:*' fzf-flags \
'--highlight-line' \
'--tabstop=4'
zstyle ':fzf-tab:*' prefix ''
zstyle ':fzf-tab:*' switch-group '<' '>'
# Use fzf-tab's tmux popup for tab completion.
zstyle ':fzf-tab:*' fzf-command ftb-tmux-popup
zstyle ':fzf-tab:*' popup-min-size 30 10
zstyle ':fzf-tab:*' popup-pad 0 0
zstyle ':fzf-tab:*' popup-fit-preview yes
if command-exists eza; then
fzf_dir_preview='eza -1 --color=always --icons $realpath'
zstyle ':fzf-tab:complete:eza:*' fzf-preview "$fzf_dir_preview"
else
fzf_dir_preview='ls -1 --color=always $realpath'
fi
zstyle ':fzf-tab:complete:cd:*' fzf-preview "$fzf_dir_preview"
zstyle ':fzf-tab:complete:ls:*' fzf-preview "$fzf_dir_preview"
if command-exists bat; then
fzf_bat_preview='bat --color=always -n -r :500'
FZF_CTRL_T_OPTS="$FZF_CTRL_T_OPTS --preview '$fzf_bat_preview {}'"
zstyle ':fzf-tab:complete:bat:*' fzf-preview "$fzf_bat_preview \$realpath"
zstyle ':fzf-tab:complete:cat:*' fzf-preview "$fzf_bat_preview \$realpath"
else
FZF_CTRL_T_OPTS="$FZF_CTRL_T_OPTS --preview 'less {}'"
fi
fi
# ==============================================================================
# Visuals
# ==============================================================================
zinit light-mode wait lucid \
atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
for @zdharma-continuum/fast-syntax-highlighting
# ==============================================================================
# Edit command line
# ==============================================================================
autoload -z edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line
# ==============================================================================
# Environment and Tool Managers
# ==============================================================================
MISE_HOME="$HOME/.local/share/mise"
MISE_ZSH_INIT="$MISE_HOME/shell/init.zsh"
export MISE_INSTALL_PATH="$MISE_HOME/bin/mise"
if ! command-exists mise; then
read -q 'REPLY?mise is not installed, install with `curl https://mise.run | sh`? [y/N]:' &&
echo && curl https://mise.run | sh
fi
if command-exists mise; then
# Activate mise. We cannot use cached-eval here as the activation script
# dynamically adjusts how it modifies PATH on each invocation.
eval "$("$MISE_INSTALL_PATH" activate zsh)"
setup-completions mise "$MISE_INSTALL_PATH" mise completions zsh
alias mi="mise"
fi
# ==============================================================================
# Prompt
# ==============================================================================
if ! command-exists starship && [ -f "$MISE_INSTALL_PATH" ]; then
read -q 'REPLY?starship is not installed, install with `mise install starship`? [y/N]:' &&
echo && "$MISE_INSTALL_PATH" install starship
fi
if command-exists starship; then
cached-eval "$(command-path starship)" starship init zsh --print-full-init
setup-completions starship "$(command-path starship)" starship completions zsh
else
echo "WARN: starship not found, skipping prompt setup" >&2
echo " install with: mise install starship" >&2
fi
# ==============================================================================
# Private Dotfiles
# ==============================================================================
if [ -f "$DOTPFILES/zshrc" ]; then
source "$DOTPFILES/zshrc"
fi
# ==============================================================================
# Tool specific setup
# ==============================================================================
# Aliases
source "$DOTZSH/aliases.zsh"
# OS specific
if [[ "$OSTYPE" == "darwin"* ]]; then source "$DOTZSH/macos.zsh"; fi
if [[ "$OSTYPE" == "linux"* ]]; then source "$DOTZSH/linux.zsh"; fi
# Utils
source "$DOTZSH/1password.zsh"
source "$DOTZSH/ansi.zsh"
source "$DOTZSH/copilot.zsh"
source "$DOTZSH/emacs.zsh"
source "$DOTZSH/less.zsh"
source "$DOTZSH/mise.zsh"
source "$DOTZSH/neovim.zsh"
source "$DOTZSH/nix.zsh"
source "$DOTZSH/restish.zsh"
source "$DOTZSH/tldr.zsh"
source "$DOTZSH/tmux.zsh"
source "$DOTZSH/zoxide.zsh"
# Development
source "$DOTZSH/containers.zsh"
source "$DOTZSH/git.zsh"
source "$DOTZSH/golang.zsh"
source "$DOTZSH/google-cloud.zsh"
source "$DOTZSH/kubernetes.zsh"
source "$DOTZSH/nodejs.zsh"
source "$DOTZSH/python.zsh"
source "$DOTZSH/ruby.zsh"
source "$DOTZSH/rust.zsh"
source "$DOTZSH/scaleway.zsh"
# ==============================================================================
# Basic Z-Shell settings
# ==============================================================================
# Disable auto-title.
DISABLE_AUTO_TITLE="true"
# Disable shared history.
unsetopt share_history
# Disable attempted correction of commands (is wrong 98% of the time).
unsetopt correctall
# ==============================================================================
# Local Overrides
# ==============================================================================
if [ -f "$HOME/.zshrc.local" ]; then
source "$HOME/.zshrc.local"
fi
autoload -U +X bashcompinit && bashcompinit