-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdot_zshrc
More file actions
211 lines (176 loc) · 6.85 KB
/
dot_zshrc
File metadata and controls
211 lines (176 loc) · 6.85 KB
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
#-----------------------------------------------------------
# @raisedadead's config files
# Copyright: Mrugesh Mohapatra <https://mrugesh.dev>
# License: ISC
#
# File name: .zshrc
#-----------------------------------------------------------
# Performance profiling (set ZPROF=true to enable)
[[ "$ZPROF" = true ]] && zmodload zsh/zprof
#-----------------------------------------------------------
# Core Settings
#-----------------------------------------------------------
umask 022
limit coredumpsize 0
# History
HISTFILE="$HOME/.zsh_history"
HISTSIZE=50000
SAVEHIST=50000
setopt INC_APPEND_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_FIND_NO_DUPS
setopt HIST_SAVE_NO_DUPS
# Options
setopt AUTO_CD
setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS
setopt CDABLE_VARS
setopt INTERACTIVECOMMENTS
stty -ixon -ixoff 2>/dev/null
# Helpers
can_haz() { whence -p "$1" >/dev/null 2>&1 }
timezsh() { for i in {1..10}; do time zsh -i -c exit; done }
# Cache and source tool-generated shell code (regenerates when binary updates)
# Usage: cached_evalz <tool> "<command>"
cached_evalz() {
local tool=$1 cmd=$2 cache_dir="$HOME/.cache/zsh-eval-cache"
can_haz "$tool" || return 1
local bin="$(whence -p "$tool")" cache="$cache_dir/$tool.zsh"
[[ -d "$cache_dir" ]] || mkdir -p "$cache_dir"
if [[ ! -f "$cache" ]] || [[ "$bin" -nt "$cache" ]]; then
eval "$cmd" > "$cache" 2>/dev/null && zcompile "$cache" 2>/dev/null
fi
source "$cache"
}
# Tmux exit code indicator (must be first precmd to capture $? before OMP)
_tmux_exit_code() { [[ -n "$TMUX" ]] && tmux set-option -qw @last_exit_code $?; }
precmd_functions=(_tmux_exit_code $precmd_functions)
# Keybindings
bindkey -e # Emacs mode
bindkey '^z' vi-cmd-mode
bindkey -M vicmd '^z' vi-add-next
function zle-keymap-select {
if [[ "$KEYMAP" == "vicmd" ]]; then
export POSH_VI_MODE="cmd"
else
unset POSH_VI_MODE
fi
# Re-generate OMP prompt (reads updated POSH_VI_MODE), then redisplay
if (( $+functions[_omp_get_prompt] )); then
eval "$(_omp_get_prompt primary --eval)"
fi
zle .reset-prompt
}
zle -N zle-keymap-select
bindkey '^[l' forward-word # Alt+L: forward word
bindkey '^[h' backward-word # Alt+H: backward word
bindkey '^[L' end-of-line # Alt+Shift+L: end of line
bindkey '^[H' beginning-of-line # Alt+Shift+H: beginning of line
# Prompt (oh-my-posh)
# v29+ uses a two-stage init: bootstrap sets a precmd that sources the real
# init from ~/.cache/oh-my-posh/init.HASH.zsh on first prompt. OMP manages
# its own cache, so we just run the bootstrap directly.
if can_haz oh-my-posh; then
eval "$(oh-my-posh init zsh --config ~/.config/oh-my-posh/config.toml)"
fi
#-----------------------------------------------------------
# Plugin Manager
#-----------------------------------------------------------
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
[[ ! -d $ZINIT_HOME ]] && mkdir -p "$(dirname $ZINIT_HOME)" && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
source "$ZINIT_HOME/zinit.zsh"
#-----------------------------------------------------------
# Load zsh-defer first
zinit light romkatv/zsh-defer
# FZF - core setup (DO NOT DEFER, need immediate availability)
source ~/.fzf.zsh
# FZF styling (can be deferred)
zsh-defer source ~/.fzf.zshrc
# Compile zinit and plugins (once daily via stamp file)
zsh-defer -c '
local stamp="$HOME/.cache/zinit-compile-stamp"
if [[ ! -f "$stamp" ]] || [[ $(( $(date +%s) - $(stat -f%m "$stamp" 2>/dev/null || echo 0) )) -gt 86400 ]]; then
zinit compile --all 2>/dev/null
touch "$stamp"
fi
'
# Load completions before compinit (per zsh-completions guidelines)
zinit light zsh-users/zsh-completions
zinit light wbingli/zsh-claudecode-completion
# Add Homebrew completions to FPATH before compinit
[[ -n "$HOMEBREW_PREFIX" ]] && FPATH="$HOMEBREW_PREFIX/share/zsh/site-functions:$FPATH"
# Add custom completions to FPATH (highest priority - added last so it's first)
[[ -d ~/.zfunc ]] && FPATH="$HOME/.zfunc:$FPATH"
# Load completion system (full rebuild once daily, cached otherwise)
autoload -Uz compinit
local zcomp="$HOME/.zcompdump"
if [[ ! -f "$zcomp" ]] || [[ $(( $(date +%s) - $(stat -f%m "$zcomp" 2>/dev/null || echo 0) )) -gt 86400 ]]; then
compinit
else
compinit -C
fi
# FZF tab (must load after compinit but before widget-wrapping plugins)
zinit wait"0a" silent for \
Aloxaf/fzf-tab
zsh-defer -c "
zstyle ':fzf-tab:*' use-fzf-default-opts yes
zstyle ':fzf-tab:*' fzf-flags --height=~60%
"
# Fast Syntax Highlighting
zinit wait"1a" silent atload"fast-theme -q XDG:catppuccin-mocha" for \
zdharma-continuum/fast-syntax-highlighting
# Suggestions
zinit wait"1b" silent atload"!_zsh_autosuggest_start" for \
zsh-users/zsh-autosuggestions
# Pair matching
zinit wait"1c" silent for \
raisedadead/zsh-smartinput
# PNPM completions
zinit wait"1d" silent atload"zpcdreplay" atclone"./zplug.zsh" atpull"%atclone" for \
g-plane/pnpm-shell-completion
# Touch file with paths
zinit wait"2a" silent for \
raisedadead/zsh-touchplus
# Wakatime
zinit wait"2b" silent for \
sobolevn/wakatime-zsh-plugin
#-----------------------------------------------------------
# Tool Integrations
#-----------------------------------------------------------
if [[ -o interactive ]]; then
# Sync inits (hooks in place before first prompt — no post-prompt re-renders)
cached_evalz atuin "atuin init zsh --disable-up-arrow"
cached_evalz zoxide "zoxide init --cmd cd --hook pwd zsh"
# Sync completions and tool inits (cached = instant source, no subprocess spawn)
cached_evalz direnv "direnv hook zsh"
cached_evalz gh "gh completion -s zsh"
cached_evalz op "op completion zsh" && compdef _op op
cached_evalz wrangler "wrangler complete zsh"
cached_evalz wt "wt shell-init zsh"
cached_evalz bd "bd completion zsh"
compdef _home home
# zsh-defer -c 'cached_evalz pkgx "pkgx --shellcode"'
fi
# File sourcing
zsh-defer source ~/.alias.zshrc
zsh-defer source ~/.private.zshrc
zsh-defer -c '[[ -f "$HOME/.local/bin/env" ]] && source "$HOME/.local/bin/env"'
zsh-defer -c '[[ -f ~/.bin/functions.sh ]] && source ~/.bin/functions.sh'
# Config compilation (recompile when source is newer than .zwc)
zsh-defer -c '
for f in ~/.zshrc ~/.zshenv ~/.alias.zshrc; do
[[ -f "$f" ]] && [[ ! -f "$f.zwc" || "$f" -nt "$f.zwc" ]] && zcompile "$f"
done
'
# Homebrew must precede /usr/bin in PATH to avoid system binaries taking priority.
# fnm must load after Homebrew so fnm-managed Node.js overrides Homebrew's Node.js.
export PATH="/opt/homebrew/bin:$PATH"
cached_evalz fnm "fnm env --use-on-cd --version-file-strategy=recursive --resolve-engines --log-level=quiet"
# Performance profiling
[[ "$ZPROF" = true ]] && zprof
#-----------------------------------------------------------
# End of .zshrc
#-----------------------------------------------------------