-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdot-zshrc
More file actions
440 lines (371 loc) · 13.5 KB
/
dot-zshrc
File metadata and controls
440 lines (371 loc) · 13.5 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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/usr/bin/env zsh
# =============================================================================
# Unified Zsh Configuration
# Consolidated from dot-profile and dot-zshrc - optimized for performance
# Terminal-centric development environment evolved since 2004
# =============================================================================
# =============================================================================
# Early Initialization - Platform Detection & Core Functions
# =============================================================================
# Platform detection functions (defined once, used everywhere)
is_macos() { [[ "$OSTYPE" == darwin* ]] }
is_linux() { [[ "$OSTYPE" == linux* ]] }
is_vm() { [[ "$(systemd-detect-virt 2>/dev/null)" =~ ^(kvm|qemu|vmware|oracle|xen|hyperv)$ ]] }
has_cmd() { command -v "$1" >/dev/null 2>&1 }
# Efficient PATH management - only add if not already present
set_path() {
if [[ -d $1 ]] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="$1:$PATH"
fi
}
# =============================================================================
# Environment Variables & PATH Setup (needed early)
# =============================================================================
# Core environment
export LC_CTYPE='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
export EDITOR="nvim"
export DOTFILES="$HOME/code/dotfiles"
# Go configuration
export GOPATH="$HOME/code/go"
export GOBIN="$HOME/.gotools"
# Node configuration
export NODE_PATH="$HOME/.node/lib/node_modules:$NODE_PATH"
export MANPATH="$HOME/.node/share/man:$MANPATH"
# Build configuration
export PKG_CONFIG_PATH="/opt/homebrew/opt/clp/lib/pkgconfig"
export WLR_NO_HARDWARE_CURSORS=1
# PATH setup (order matters - most specific to least specific)
set_path "$HOME/.local/bin"
set_path "$GOBIN"
set_path "$HOME/.cargo/bin"
set_path "$HOME/.jenv/bin"
set_path "$HOME/.node/bin"
set_path "$HOME/.vim/plugged/vim-iced/bin"
# macOS specific paths
if is_macos; then
set_path "/opt/homebrew/bin"
set_path "/opt/homebrew/sbin"
set_path "/usr/local/opt/gnu-sed/libexec/gnubin"
set_path "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin"
set_path "/opt/homebrew-cask/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin"
set_path "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin"
set_path "/Library/TeX/texbin"
fi
# Linux specific paths
if is_linux; then
set_path "/var/lib/snapd/snap/bin"
fi
# VM-specific settings (UTM/QEMU)
if is_linux && is_vm; then
export MESA_LOADER_DRIVER_OVERRIDE=zink
fi
# System paths (these should come after user paths)
set_path "/usr/local/bin"
set_path "/usr/local/sbin"
set_path "/usr/bin"
set_path "/bin"
set_path "/usr/sbin"
set_path "/sbin"
set_path "/usr/local/go/bin"
set_path "$HOME/.local/bin"
# Cargo environment
[[ -f "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env"
# =============================================================================
# Zsh Configuration & Completion System
# =============================================================================
# Initialize completion system first
autoload -Uz compinit
compinit
# Brew completions (macOS)
if is_macos && has_cmd "brew"; then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
fi
# =============================================================================
# History Configuration (defined once)
# =============================================================================
export HISTSIZE=50000
export SAVEHIST=50000
export HISTFILE="$HOME/.zsh_history"
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_SAVE_NO_DUPS
setopt SHARE_HISTORY
setopt APPEND_HISTORY
setopt INC_APPEND_HISTORY
# Key bindings
bindkey '^R' history-incremental-pattern-search-backward
# Reduce delay for vi mode
export KEYTIMEOUT=1
# =============================================================================
# Zinit Plugin Manager
# =============================================================================
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
if [[ ! -f "${ZINIT_HOME}/zinit.zsh" ]]; then
echo "🚀 Zinit (modern zsh plugin manager) not found."
echo "Would you like to install it for better performance and features? (y/n)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
echo "Installing Zinit..."
bash -c "$(curl -fsSL https://git.io/zinit-install)"
[[ -f "${ZINIT_HOME}/zinit.zsh" ]] && source "${ZINIT_HOME}/zinit.zsh"
ZINIT_AVAILABLE=true
else
echo "Using basic zsh setup. You can install Zinit later with:"
echo "bash -c \"\$(curl -fsSL https://git.io/zinit-install)\""
ZINIT_AVAILABLE=false
fi
else
source "${ZINIT_HOME}/zinit.zsh"
ZINIT_AVAILABLE=true
fi
# =============================================================================
# Plugin Loading
# =============================================================================
if [[ "$ZINIT_AVAILABLE" == "true" ]]; then
# Load OMZ framework and essential libraries first
zinit snippet OMZL::git.zsh
zinit snippet OMZL::grep.zsh
zinit snippet OMZL::history.zsh
zinit snippet OMZL::key-bindings.zsh
zinit snippet OMZL::completion.zsh
zinit snippet OMZL::theme-and-appearance.zsh
# Load core OMZ plugins
zinit snippet OMZP::git
zinit snippet OMZP::common-aliases
zinit snippet OMZP::vi-mode
# Conditional plugin loading based on available commands
has_cmd "tmux" && zinit snippet OMZP::tmux
has_cmd "docker" && zinit snippet OMZP::docker
has_cmd "kubectl" && zinit snippet OMZP::kubectl
has_cmd "pip" && zinit snippet OMZP::pip
has_cmd "python" && zinit snippet OMZP::python
has_cmd "mvn" && zinit snippet OMZP::mvn
has_cmd "gradle" && zinit snippet OMZP::gradle
# Platform-specific plugins
is_macos && has_cmd "brew" && zinit snippet OMZP::brew
is_linux && has_cmd "dnf" && zinit snippet OMZP::dnf
# Modern zsh enhancements
zinit light "zsh-users/zsh-autosuggestions"
zinit light "zdharma-continuum/fast-syntax-highlighting"
zinit light "zsh-users/zsh-history-substring-search"
zinit light "zsh-users/zsh-completions" # Add more completions
# Load gentoo theme
zinit snippet OMZT::gentoo
else
# Fallback: Basic setup without plugin manager
echo "Using basic zsh setup..."
# Essential aliases
alias ll='ls -la'
alias la='ls -A'
alias l='ls -CF'
# Basic git aliases
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git pull'
alias gd='git diff'
alias gb='git branch'
alias gco='git checkout'
# Basic docker aliases
has_cmd "docker" && {
alias dps='docker ps'
alias dpa='docker ps -a'
alias di='docker images'
}
# Basic kubectl aliases
has_cmd "kubectl" && {
alias k='kubectl'
alias kg='kubectl get'
alias kd='kubectl describe'
}
# Simple prompt
autoload -U colors && colors
PS1="%F{green}%n@%m%f %F{blue}%~%f %F{green}$%f "
fi
# =============================================================================
# Cross-Platform Aliases & Tools
# =============================================================================
# Clipboard integration
if is_macos; then
alias clip='pbcopy'
alias paste='pbpaste'
alias open='open'
elif has_cmd 'xclip'; then
alias clip='xclip -selection clipboard'
alias paste='xclip -selection clipboard -o'
alias open='xdg-open'
elif has_cmd 'wl-copy'; then
alias clip='wl-copy'
alias paste='wl-paste'
alias open='xdg-open'
fi
# Package manager shortcuts
if has_cmd 'brew'; then
alias install='brew install'
alias search='brew search'
alias update='brew update && brew upgrade'
elif has_cmd 'dnf'; then
alias install='sudo dnf install'
alias search='dnf search'
alias update='sudo dnf upgrade'
fi
# Modern tool aliases (only if available)
has_cmd 'eza' && alias ls='eza --color=auto --icons'
has_cmd 'bat' && alias cat='bat'
has_cmd 'rg' && alias grep='rg'
# Better pager
has_cmd 'most' && export PAGER="most"
# Core aliases
alias vim='nvim'
alias wiki='nvim +VimwikiIndex'
alias dock='eval $(docker-machine env default)'
alias gdrive='rclone mount drive: ~/GoogleDrive/My\ Drive --daemon --fast-list --drive-use-trash=true --allow-non-empty'
alias rgdrive='fusermount -u ~/GoogleDrive/My\ Drive'
alias t='todo.sh'
alias todo='vim ~/GoogleDrive/My\ Drive/todo-txt/todo.txt'
alias doroutes='sh $HOME/code/jek/vpn-tun.sh'
# =============================================================================
# Custom Functions
# =============================================================================
# Lazy loading kubectl completion for performance
kubectl() {
# Remove this function to avoid infinite recursion
unset -f kubectl
# Load kubectl completion now that we need it
if command -v kubectl >/dev/null 2>&1; then
source <(command kubectl completion zsh)
fi
# Now run the actual kubectl command
command kubectl "$@"
}
# Smart project navigation
code() {
SVC=$1
if [[ ! -z $SVC"" ]]; then
# Search for the service in multiple locations
for base in "$HOME/code/ss/" "$HOME/code/" "$HOME/code/jek/" "" "$HOME/code/ColdBrew/"; do
if [[ -d $base$SVC ]]; then
tmux_code $base/$SVC $(basename $SVC)
return
fi
done
fi
echo "Could NOT find '$SVC' starting in ~/code"
tmux_code ~/code code
}
# Enhanced tmux project workspace
tmux_code() {
local project_path=$1
local window_name=$2
# Create session if it doesn't exist
if ! tmux list-sessions 2>/dev/null | grep -q "^work:"; then
tmux new-session -d -s work -c "$project_path"
fi
# Create new window with project name
tmux new-window -t work -n "$window_name" -c "$project_path"
# Recreate the tmuxifier layout
tmux split-window -h -p 20 -c "$project_path"
tmux select-pane -t 1
tmux split-window -v -p 20 -c "$project_path"
tmux split-window -h -p 50 -c "$project_path"
# Select main pane
tmux select-pane -t 0
# Attach to session if not already in tmux
if [ -z "$TMUX" ]; then
tmux attach-session -t work
fi
}
# Python virtual environment helper
enl_venv() {
if [ -d ".venv" ]; then
source .venv/bin/activate
elif [ -d "venv" ]; then
source venv/bin/activate
fi
}
# Process management functions
kill_falcon() {
ps aux | grep falcon.Agent | grep root | awk '{print $2}' | xargs sudo kill -9
}
kill_falcon_always() {
sudo /bin/bash -c "while true; do ps aux | grep falcon.Agent | grep -v grep |grep root | awk '{print \$2}' | xargs kill -9 ; sleep 5; done"
}
# Dynamic PKG_CONFIG_PATH setup
set_pkg_config() {
export PKG_CONFIG_PATH=$(find /opt/homebrew/Cellar -name 'pkgconfig' -type d | grep lib/pkgconfig | tr '\n' ':' | sed s/.$//)
}
# =============================================================================
# Tool Integrations (Lazy Loaded)
# =============================================================================
# fzf integration
if has_cmd "fzf"; then
source <(fzf --zsh) 2>/dev/null || {
# Fallback for older fzf versions
[[ -f ~/.fzf.zsh ]] && source ~/.fzf.zsh
}
fi
# zoxide integration (smart cd)
has_cmd "zoxide" && eval "$(zoxide init zsh)"
# yazi integration (cd to directory on exit)
if has_cmd "yazi"; then
y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
yazi "$@" --cwd-file="$tmp"
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
builtin cd -- "$cwd"
fi
rm -f -- "$tmp"
}
fi
# kubectl completion will be lazy loaded when first used
# NVM - Load default Node version automatically
export NVM_DIR="$HOME/.nvm"
# Support both Homebrew and standard nvm installations
if [ -s "/opt/homebrew/opt/nvm/nvm.sh" ]; then
\. "/opt/homebrew/opt/nvm/nvm.sh" --no-use
elif [ -s "$NVM_DIR/nvm.sh" ]; then
\. "$NVM_DIR/nvm.sh" --no-use
fi
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Auto-load default Node version
if command -v nvm >/dev/null 2>&1; then
nvm use default --silent
fi
# Optional: Auto-switch Node version based on .nvmrc when changing directories
if type nvm_find_nvmrc &>/dev/null; then
autoload -U add-zsh-hook
load-nvmrc() {
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then
nvm use --silent
fi
elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default --silent
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
fi
# RVM (lazy loaded for performance)
rvm() {
unset -f rvm
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
rvm "$@"
}
# Load secrets if available
[[ -f ~/.secret.rc ]] && source ~/.secret.rc
# =============================================================================
# Final Setup
# =============================================================================
# Ensure colors work properly
autoload -U colors && colors
# Added by Antigravity
export PATH="/Users/ankurshrivastava/.antigravity/antigravity/bin:$PATH"