|
1 | | -# Environment variables |
2 | | -export LANG=en_US.UTF-8 |
3 | | -export EDITOR="nvim" |
4 | | -export MANPAGER="nvim +Man!" |
5 | | -export VISUAL="$EDITOR" |
6 | | -export GOPATH="$HOME/go" |
7 | | -export KUBECONFIG="$HOME/.kube/config" |
8 | | -export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow' |
9 | | -export STARSHIP_CONFIG="$HOME/.config/starship/starship.toml" |
10 | | -export ARCH="$(uname -m)" |
11 | | - |
12 | | -# Directory paths |
13 | | -export GARDEN=("$HOME/Library/Mobile Documents/com~apple~CloudDocs/Documents/The Garden") |
14 | | -export ICLOUD=("$HOME/Library/Mobile Documents/com~apple~CloudDocs") |
15 | | -export REPOS="$HOME/code" |
16 | | -export GITUSER="$USER" |
17 | | -export GHREPOS="$REPOS/$GITUSER" |
18 | | -export XDG_CONFIG_HOME="$HOME"/.config |
19 | | -export DOTFILES="$HOME/code/$GITUSER/dotfiles" |
20 | | - |
21 | | -# Update PATH |
22 | | -typeset -U path |
23 | | - |
24 | | -# Homebrew first (arch-aware) |
25 | | -if [[ $ARCH == arm64 ]]; then |
26 | | - path=(/opt/homebrew/bin /opt/homebrew/sbin $path) |
27 | | -else |
28 | | - path=(/usr/local/bin /usr/local/sbin $path) |
29 | | -fi |
30 | | - |
31 | | -# User-level tools |
32 | | -path+=( |
33 | | - $HOME/.local/bin |
34 | | - $GOPATH/bin |
35 | | - $HOME/.cargo/bin |
36 | | - $HOME/.vimpkg/bin |
37 | | -) |
38 | | - |
39 | | -export PATH |
40 | | - |
41 | | -# Autoload custom functions |
| 1 | +# Resolve directory of this file (follows symlinks) |
42 | 2 | ZSHRC_DIR="${${(%):-%N}:A:h}" |
43 | | -fpath=("$ZSHRC_DIR/functions" $fpath) |
44 | | -autoload -Uz awsprofile gcpprofile gcpproject gcpdrop devops |
45 | | - |
46 | | -# Cache brew prefix (avoid subshell on every startup) |
47 | | -if [[ "$ARCH" == "arm64" ]]; then |
48 | | - _BREW_PREFIX="/opt/homebrew" |
49 | | -else |
50 | | - _BREW_PREFIX="/usr/local" |
51 | | -fi |
52 | | - |
53 | | -# ZSH configuration |
54 | | -setopt prompt_subst |
55 | | -zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' |
56 | | -ZSH_COMPDUMP="${ZDOTDIR:-$HOME}/.zcompdump-${HOST}" |
57 | | -autoload -Uz compinit bashcompinit |
58 | | -if [[ -n "$ZSH_COMPDUMP"(#qN.mh+24) ]]; then |
59 | | - compinit -d "$ZSH_COMPDUMP" |
60 | | -else |
61 | | - compinit -d "$ZSH_COMPDUMP" -C |
62 | | -fi |
63 | | -bashcompinit |
64 | | - |
65 | | -# kubectl lazy-load completion |
66 | | -if (( $+commands[kubectl] )); then |
67 | | - _kubectl_lazy() { |
68 | | - unfunction _kubectl_lazy |
69 | | - source <(command kubectl completion zsh) |
70 | | - _kubectl "$@" |
71 | | - } |
72 | | - compdef _kubectl_lazy kubectl |
73 | | -fi |
74 | | - |
75 | | -# AWS CLI autocompletion |
76 | | -if [[ "$ARCH" == "arm64" ]]; then |
77 | | - # Apple Silicon |
78 | | - complete -C '/opt/homebrew/bin/aws_completer' aws |
79 | | -elif [[ "$ARCH" == "x86_64" ]]; then |
80 | | - # Intel Macs |
81 | | - complete -C '/usr/local/bin/aws_completer' aws |
82 | | -fi |
83 | | - |
84 | | -# gcloud lazy-load (path + completion) |
85 | | -if (( $+commands[gcloud] )); then |
86 | | - _gcloud_lazy() { |
87 | | - unfunction _gcloud_lazy |
88 | | - |
89 | | - # Source path and completion based on arch |
90 | | - if [[ "$ARCH" == "arm64" ]]; then |
91 | | - [[ -f /opt/homebrew/share/google-cloud-sdk/path.zsh.inc ]] && source /opt/homebrew/share/google-cloud-sdk/path.zsh.inc |
92 | | - [[ -f /opt/homebrew/share/google-cloud-sdk/completion.zsh.inc ]] && source /opt/homebrew/share/google-cloud-sdk/completion.zsh.inc |
93 | | - elif [[ "$ARCH" == "x86_64" ]]; then |
94 | | - [[ -f /usr/local/share/google-cloud-sdk/path.zsh.inc ]] && source /usr/local/share/google-cloud-sdk/path.zsh.inc |
95 | | - [[ -f /usr/local/share/google-cloud-sdk/completion.zsh.inc ]] && source /usr/local/share/google-cloud-sdk/completion.zsh.inc |
96 | | - fi |
97 | | - |
98 | | - _gcloud "$@" |
99 | | - } |
100 | | - compdef _gcloud_lazy gcloud |
101 | | -fi |
102 | | - |
103 | | -# Plugin sourcing |
104 | | -source ${_BREW_PREFIX}/share/zsh-autosuggestions/zsh-autosuggestions.zsh |
105 | | - |
106 | | -# Key bindings |
107 | | -bindkey '^w' forward-word |
108 | | -bindkey '^e' autosuggest-accept |
109 | | -bindkey '^u' autosuggest-toggle |
110 | | -bindkey '^L' vi-forward-word |
111 | | -bindkey '^k' up-line-or-search |
112 | | -bindkey '^j' down-line-or-search |
113 | | -bindkey 'jj' vi-cmd-mode |
114 | | - |
115 | | -# Initialize starship prompt |
116 | | -eval "$(starship init zsh)" |
117 | | - |
118 | | -# Base aliases |
119 | | -alias la=tree |
120 | | -alias cat="bat" |
121 | | -alias cl='clear' |
122 | | -alias l="eza -l --icons --git -a" |
123 | | -alias ls="eza --icons" |
124 | | -alias lt="eza --tree --level=2 --long --icons --git" |
125 | | -alias of="fzf --preview 'bat --style=numbers --color=always --line-range :500 {}' | xargs nvim" |
126 | | -alias cp="cp -riv" |
127 | | -alias rm="rm -i" |
128 | | -alias http="xh" |
129 | | -alias rr='ranger' |
130 | | -alias ff="fastfetch" |
131 | | -alias v="nvim" |
132 | | - |
133 | | - |
134 | | -# Git aliases |
135 | | -alias gc="git commit -m" |
136 | | -alias gca="git commit -a -m" |
137 | | -alias gp="git push origin HEAD" |
138 | | -alias gpu="git pull origin" |
139 | | -alias gs="git status --short" |
140 | | -alias glog="git log --graph --topo-order --pretty='%w(100,0,6)%C(yellow)%h%C(bold)%C(red)%d %C(cyan)%ar %C(green)%an%n%C(bold)%C(white)%s %N' --abbrev-commit" |
141 | | -alias gdiff="git diff" |
142 | | -alias gco="git checkout" |
143 | | -alias gb='git branch' |
144 | | -alias gba='git branch -a' |
145 | | -alias gadd='git add' |
146 | | -alias ga='git add -p' |
147 | | -alias gcoall='git checkout -- .' |
148 | | -alias gr='git remote' |
149 | | -alias gre='git reset' |
150 | | -alias gitlogue='gitlogue --background false' |
151 | | - |
152 | | -# Docker aliases |
153 | | -alias dco="docker compose" |
154 | | -alias dcu="docker compose up -d" |
155 | | -alias dcd="docker compose down" |
156 | | -alias dps="docker ps" |
157 | | -alias dpa="docker ps -a" |
158 | | -alias dl="docker ps -l -q" |
159 | | -alias dx="docker exec -it" |
160 | | -alias minikube-start="minikube start --addons=metrics-server" |
161 | | - |
162 | | -# Directory navigation aliases |
163 | | -alias ..="cd .." |
164 | | -alias ...="cd ../.." |
165 | | -alias ....="cd ../../.." |
166 | | -alias .....="cd ../../../.." |
167 | | -alias ......="cd ../../../../.." |
168 | | -alias garden="cd \$GARDEN" |
169 | | -alias icloud="cd \$ICLOUD" |
170 | | -alias xdg="cd \"$XDG_CONFIG_HOME/\"" |
171 | | -alias repos="cd $REPOS" |
172 | | -alias ghrepos="cd $GHREPOS" |
173 | | -alias work="cd $REPOS/work/" |
174 | | - |
175 | | -# Kubernetes aliases |
176 | | -alias k="kubectl" |
177 | | -alias ka="kubectl apply -f" |
178 | | -alias kg="kubectl get" |
179 | | -alias kd="kubectl describe" |
180 | | -alias kdel="kubectl delete" |
181 | | -alias kl="kubectl logs" |
182 | | -alias kgpo="kubectl get pod" |
183 | | -alias kgd="kubectl get deployments" |
184 | | -alias kc="kubectx" |
185 | | -alias kns="kubens" |
186 | | -alias kl="kubectl logs -f" |
187 | | -alias ke="kubectl exec -it" |
188 | | -alias kcns='kubectl config set-context --current --namespace' |
189 | | -alias k8s='nvim +"lua require(\"kubectl\").open()"' |
190 | | - |
191 | | -# Terraform aliases |
192 | | -alias tf="terraform" |
193 | | -alias tfsl="terraform state list" |
194 | | -alias tfdev="terraform apply -var-file=dev.tfvars" |
195 | | -alias tfprod="terraform apply -var-file=prod.tfvars" |
196 | | - |
197 | | -# Tmux aliases |
198 | | -alias ta="tmux attach || tmux new -A -s default" |
199 | | -alias tn="tmux new-session -s \$(pwd | sed 's/.*\///g')" |
200 | | -alias td="tmux detach" |
201 | | -alias mat='osascript -e "tell application \"System Events\" to key code 126 using {command down}" && tmux neww "cmatrix"' |
202 | | - |
203 | | -# Create a tmux layout for dev with editor, ai, and terminal |
204 | | -tml() { |
205 | | - local current_dir="${PWD}" |
206 | | - local session_name="${current_dir##*/}" |
207 | | - local editor_pane ai_pane |
208 | | - local ai="opencode" |
209 | | - # If not inside tmux, create a session and run tml inside it |
210 | | - if [[ -z "$TMUX" ]]; then |
211 | | - tmux new-session -d -s "$session_name" -c "$current_dir" |
212 | | - tmux send-keys -t "$session_name" "tml $ai" C-m |
213 | | - tmux attach -t "$session_name" |
214 | | - return |
215 | | - fi |
216 | | - |
217 | | - # Already inside tmux — set up the layout |
218 | | - editor_pane=$(tmux display-message -p '#{pane_id}') |
219 | | - tmux split-window -v -p 15 -c "$current_dir" |
220 | | - |
221 | | - tmux select-pane -t "$editor_pane" |
222 | | - tmux split-window -h -p 30 -c "$current_dir" |
223 | | - ai_pane=$(tmux display-message -p '#{pane_id}') |
224 | | - tmux send-keys -t "$ai_pane" "$ai" C-m |
225 | | - tmux send-keys -t "$editor_pane" "$EDITOR ." C-m |
226 | | - |
227 | | - tmux select-pane -t "$editor_pane" |
228 | | -} |
229 | | - |
230 | | -# Password generation |
231 | | -pg() { |
232 | | - local password |
233 | | - password=$(pwgen -sy -1 15) |
234 | | - printf "%s" "$password" | pbcopy |
235 | | - echo "Password: $password (copied to clipboard)" |
236 | | -} |
237 | | - |
238 | | -# Find and copy IP address to clipboard |
239 | | -ip() { |
240 | | - local ip_address |
241 | | - ip_address=$(curl -s4 https://ip.me) |
242 | | - printf "%s" "$ip_address" | pbcopy # no newline |
243 | | - echo "IP address: $ip_address (copied to clipboard)" |
244 | | -} |
245 | | - |
246 | | -# Cloud aliases |
247 | | -alias aws-profile=awsprofile |
248 | | -alias gcp-profile=gcpprofile |
249 | | -alias gcp-project=gcpproject |
250 | | -alias gcp-drop=gcpdrop |
251 | | - |
252 | | -# Sesh session management |
253 | | -function ss() { |
254 | | - { |
255 | | - exec </dev/tty |
256 | | - exec <&1 |
257 | | - local session |
258 | | - session=$(sesh list -t -c | fzf --height 40% --reverse --border-label ' sesh ' --border --prompt '⚡ attach to session > ') |
259 | | - zle reset-prompt > /dev/null 2>&1 || true |
260 | | - [[ -z "$session" ]] && return |
261 | | - sesh connect $session |
262 | | - } |
263 | | -} |
264 | | - |
265 | | -# Copy-cat function: cap |
266 | | -cap() { |
267 | | - # If no arguments and nothing on stdin, show usage |
268 | | - if [[ -t 0 && $# -eq 0 ]]; then |
269 | | - echo "Usage: cap [file ...]" |
270 | | - return 1 |
271 | | - fi |
272 | | - |
273 | | - if [[ $# -gt 0 ]]; then |
274 | | - # Remove trailing whitespace/newlines before copying |
275 | | - content=$(cat "$@" | sed -e 's/[[:space:]]*$//') |
276 | | - printf "%s" "$content" | pbcopy |
277 | | - echo "Copied contents of: $* to clipboard" |
278 | | - else |
279 | | - # Handle stdin input |
280 | | - content=$(cat | sed -e 's/[[:space:]]*$//') |
281 | | - printf "%s" "$content" | pbcopy |
282 | | - echo "Copied input from stdin to clipboard" |
283 | | - fi |
284 | | -} |
285 | | - |
286 | | -# Finder function: open current directory in Finder |
287 | | -finder() { |
288 | | - open . |
289 | | -} |
290 | | -zle -N finder |
291 | | -bindkey '^f' finder |
292 | | - |
293 | | -# Navigation functions |
294 | | -cx() { cd "$@" && l; } |
295 | | -fcd() { cd "$(find . -type d -not -path '*/.*' | fzf)" && l; } |
296 | | -f() { echo "$(find . -type f -not -path '*/.*' | fzf)" | pbcopy } |
297 | | -fv() { nvim "$(find . -type f -not -path '*/.*' | fzf)" } |
298 | | - |
299 | | -# Yank to the system clipboard |
300 | | -function vi-yank-xclip { |
301 | | - zle vi-yank |
302 | | - echo "$CUTBUFFER" | pbcopy -i |
303 | | -} |
304 | | -zle -N vi-yank-xclip |
305 | | -bindkey -M vicmd 'y' vi-yank-xclip |
306 | | - |
307 | | -# Duckduckgo search |
308 | | -function ddg() { |
309 | | - open "https://duckduckgo.com/?q=$*" |
310 | | -} |
311 | | - |
312 | | -# Google search |
313 | | -function google() { |
314 | | - open "https://www.google.com/search?q=$*" |
315 | | -} |
316 | | - |
317 | | -# Load additional tools |
318 | | -[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh |
319 | | - |
320 | | -# thefuck lazy wrapper - loads on first use |
321 | | -if (( $+commands[thefuck] )); then |
322 | | - fuck() { |
323 | | - unfunction fuck |
324 | | - eval $(thefuck --alias) |
325 | | - fuck "$@" |
326 | | - } |
327 | | -fi |
328 | | - |
329 | | -# stern lazy-load completion |
330 | | -if (( $+commands[stern] )); then |
331 | | - _stern_lazy() { |
332 | | - unfunction _stern_lazy |
333 | | - source <(command stern --completion=zsh) |
334 | | - _stern "$@" |
335 | | - } |
336 | | - compdef _stern_lazy stern |
337 | | -fi |
338 | | - |
339 | | -# helm lazy-load completion |
340 | | -if (( $+commands[helm] )); then |
341 | | - _helm_lazy() { |
342 | | - unfunction _helm_lazy |
343 | | - source <(command helm completion zsh) |
344 | | - _helm "$@" |
345 | | - } |
346 | | - compdef _helm_lazy helm |
347 | | -fi |
348 | | - |
349 | | -# zoxide lazy wrappers - loads on first use of z or zi |
350 | | -if (( $+commands[zoxide] )); then |
351 | | - z() { |
352 | | - unfunction z zi |
353 | | - eval "$(zoxide init zsh)" |
354 | | - z "$@" |
355 | | - } |
356 | | - |
357 | | - zi() { |
358 | | - unfunction z zi |
359 | | - eval "$(zoxide init zsh)" |
360 | | - zi "$@" |
361 | | - } |
362 | | -fi |
363 | | - |
364 | | -eval "$(atuin init zsh)" |
365 | | - |
366 | | -# Terraform completion |
367 | | -if [[ "$ARCH" == "arm64" ]]; then |
368 | | - # Apple Silicon |
369 | | - complete -o nospace -C /opt/homebrew/bin/terraform terraform |
370 | | -elif [[ "$ARCH" == "x86_64" ]]; then |
371 | | - # Intel Macs |
372 | | - complete -o nospace -C /usr/local/bin/terraform terraform |
373 | | -fi |
374 | 3 |
|
375 | | -# Source zsh-syntax-highlighting last (must wrap all widgets after they're registered) |
376 | | -source ${_BREW_PREFIX}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh |
| 4 | +# Source modular config files |
| 5 | +source "$ZSHRC_DIR/env.zsh" # Environment variables, PATH, brew prefix |
| 6 | +source "$ZSHRC_DIR/options.zsh" # setopt, zstyle, compinit |
| 7 | +source "$ZSHRC_DIR/completions.zsh" # Lazy-load completions (kubectl, aws, gcloud, etc.) |
| 8 | +source "$ZSHRC_DIR/plugins.zsh" # Plugin sourcing (autosuggestions, starship, fzf, etc.) |
| 9 | +source "$ZSHRC_DIR/functions.zsh" # Shell functions |
| 10 | +source "$ZSHRC_DIR/aliases.zsh" # Aliases |
| 11 | +source "$ZSHRC_DIR/keybindings.zsh" # Key bindings (after functions — registers zle widgets) |
0 commit comments