-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_zshrc
More file actions
303 lines (259 loc) · 15.7 KB
/
dot_zshrc
File metadata and controls
303 lines (259 loc) · 15.7 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
# Minimal Unix-aligned zshrc
# Target: <100ms startup
# ─────────────────────────────────────────────────────────────────────────────
# Core
# ─────────────────────────────────────────────────────────────────────────────
setopt AUTO_CD AUTO_PUSHD PUSHD_SILENT PUSHD_TO_HOME
setopt HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
setopt NO_BEEP INTERACTIVE_COMMENTS
HISTFILE=~/.zsh_history
HISTSIZE=50000
SAVEHIST=50000
export EDITOR='nvim' VISUAL='nvim' GPG_TTY=$TTY
export HOMEBREW_NO_ENV_HINTS=1
# ─────────────────────────────────────────────────────────────────────────────
# PATH
# ─────────────────────────────────────────────────────────────────────────────
typeset -U path
path=(~/.local/bin ~/.cargo/bin ~/.bun/bin ~/.mint/bin $path)
# ─────────────────────────────────────────────────────────────────────────────
# Completions (early init, -C uses cached .zcompdump for speed)
# ─────────────────────────────────────────────────────────────────────────────
autoload -Uz compinit && compinit -C
# ─────────────────────────────────────────────────────────────────────────────
# Cached inits (~50ms savings)
# Regenerate: rm ~/.cache/zsh/*.zsh
# ─────────────────────────────────────────────────────────────────────────────
_cache=~/.cache/zsh
[[ -d $_cache ]] || mkdir -p $_cache
_cached_init() {
local name=$1 cmd=$2
local cache=$_cache/${name}.zsh
local bin=${3:-$name}
# Invalidate cache when binary changes (brew upgrade, mise update, etc.)
local bin_path=$(whence -p $bin 2>/dev/null)
if [[ -n $bin_path && -f $cache && $bin_path -nt $cache ]]; then
rm -f $cache
fi
[[ -f $cache ]] || eval "$cmd" > $cache 2>/dev/null
source $cache
}
_cached_init mise "mise activate zsh"
_cached_init starship "starship init zsh"
_cached_init zoxide "zoxide init zsh"
source "$(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
_cached_init atuin "atuin init zsh"
_cached_init just "just --completions zsh"
_cached_init direnv "direnv hook zsh"
# ─────────────────────────────────────────────────────────────────────────────
# FZF
# ─────────────────────────────────────────────────────────────────────────────
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS="--preview 'bat --color=always --line-range=:200 {}'"
export FZF_ALT_C_COMMAND='fd --type d --hidden --exclude .git'
export FZF_ALT_C_OPTS="--preview 'eza --tree --level=2 --icons {}'"
_cached_init fzf "fzf --zsh"
# WezTerm shell integration (OSC 7/133)
# Skip semantic zones (OSC 133 PS1 wrapping) - causes autocomplete text mirroring with zsh-autosuggestions
[[ "$TERM_PROGRAM" == "WezTerm" ]] && WEZTERM_SHELL_SKIP_SEMANTIC_ZONES=1 source "/Applications/WezTerm.app/Contents/Resources/wezterm.sh"
# ─────────────────────────────────────────────────────────────────────────────
# Aliases
# ─────────────────────────────────────────────────────────────────────────────
alias gs='git status' ga='git add' gc='git commit -m' gp='git push'
alias gl='git log --oneline --graph --all -20' gd='git diff' lg='lazygit'
alias ll='eza -la --icons' lt='eza --tree --level=2 --icons'
alias dev='cd ~/Development' vim='nvim' vi='nvim'
alias prc='gh pr create' prl='gh pr list' prv='gh pr view'
alias prco='gh pr checkout' prm='gh pr merge --squash --delete-branch'
alias iss='gh issue list' isc='gh issue create'
alias csl='gh cs list' css='gh cs ssh' csc='gh cs create' csd='gh cs delete'
alias em="emacsclient -c -a ''" et="emacsclient -t -a ''" ek="emacsclient -e '(kill-emacs)'"
# Just (modern make)
alias j='just' jl='just --list' je='just --evaluate'
alias jc='just --choose' # fzf recipe picker
alias ju='just --justfile ~/.user.justfile' # global recipes
# Modern coreutils
alias ps='procs' dns='doggo' bench='hyperfine'
# UniFi/Network
alias devprocs='procs --tree | grep -E "(node|python|ruby|go|java)"'
alias ports='lsof -iTCP -sTCP:LISTEN -n -P'
alias myip='curl -s ifconfig.me && echo'
alias localip='ipconfig getifaddr en0'
alias flushdns='sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder && echo "DNS flushed"'
alias netauto='~/.local/bin/network-auto'
alias vpn='scutil --nc start "UID Enterprise VPN"'
alias vpn-off='scutil --nc stop "UID Enterprise VPN"'
alias vpn-status='scutil --nc status "UID Enterprise VPN"'
# Network security (coffee shop mode)
alias wifi-info='unifi wifi'
alias wifi-scan='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s'
coffee() {
echo "Activating coffee shop security mode..."
# Ensure VPN is connected on untrusted networks
local ssid=$(networksetup -getairportnetwork en0 | sed 's/Current Wi-Fi Network: //')
if [[ "$ssid" != "unimartus" && -n "$ssid" ]]; then
echo "Untrusted network: $ssid"
scutil --nc start "UID Enterprise VPN" 2>/dev/null || echo "VPN not available"
fi
# Disable sharing services
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist 2>/dev/null
# Show current security status
echo "Firewall: $(sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate 2>/dev/null | grep -o 'enabled\|disabled')"
echo "VPN: $(scutil --nc status 'UID Enterprise VPN' 2>/dev/null | head -1)"
}
# Smart cat
cat() { [[ -t 1 ]] && command bat "$@" || command cat "$@"; }
# Quick capture
inbox() { [[ -n "$1" ]] && echo "$(date +%Y-%m-%d\ %H:%M) $*" >> ~/inbox.txt || [[ -f ~/inbox.txt ]] && cat ~/inbox.txt; }
inbox-process() { claude -p "prioritize and categorize, output markdown checklist" < ~/inbox.txt; }
# ─────────────────────────────────────────────────────────────────────────────
# Claude CLI
# ─────────────────────────────────────────────────────────────────────────────
alias ai='claude -p'
alias aic='claude -c'
alias aim='claude --model haiku -p'
alias air='claude -r'
# Pipe patterns
explain() { "$@" 2>&1 | claude -p "explain this output concisely"; }
fixcmd() { echo "$*" | claude -p "fix this command, output only the corrected command"; }
summarize() { claude -p "summarize in 3 bullets" < "$1"; }
# Git + Claude
review() { git diff "${@:---cached}" | claude -p "review this diff, be terse"; }
whatchanged() { git log --oneline -10 | claude -p "summarize recent work in 2-3 bullets"; }
gcai() {
local msg=$(git diff --cached | claude -p "write conventional commit msg, one line, no quotes")
[[ -n "$msg" ]] && git commit -m "$msg" || echo "no message generated"
}
# FZF + Claude
aif() {
local file=$(fd -t f | fzf --preview 'bat --color=always {}')
[[ -n "$file" ]] && claude -p "$* (analyzing $file)" < "$file"
}
aihistory() {
local cmd=$(atuin search --format '{command}' | fzf)
[[ -n "$cmd" ]] && echo "$cmd" | claude -p "explain what this command does"
}
# ─────────────────────────────────────────────────────────────────────────────
# Streaming/OBS
# ─────────────────────────────────────────────────────────────────────────────
# OBS quick controls (uses ~/.local/bin/obs)
alias stream='obs stream'
alias rec='obs record'
alias scenes='obs scenes'
alias ss='obs screenshot'
# Stream monitoring
alias streamstat='obs stats && obs stream status'
# Watch any stream in terminal (low latency)
watch-stream() { streamlink "$1" "${2:-best}" --player mpv; }
alias twitch='watch-stream https://twitch.tv/'
alias yt-live='watch-stream'
# Download/capture
alias ytdl='yt-dlp -f "bestvideo[height<=1080]+bestaudio/best"'
alias ytmp3='yt-dlp -x --audio-format mp3'
alias ytclip='yt-dlp --download-sections'
# ffmpeg helpers
alias ffprobe-json='ffprobe -v quiet -print_format json -show_format -show_streams'
vidinfo() { ffprobe -v error -show_entries format=duration,size,bit_rate -of default=noprint_wrappers=1 "$1"; }
gif() { ffmpeg -i "$1" -vf "fps=15,scale=640:-1:flags=lanczos" -c:v gif "${1%.*}.gif"; }
clip() { ffmpeg -ss "$2" -i "$1" -t "$3" -c copy "${1%.*}_clip.${1##*.}"; }
compress() { ffmpeg -i "$1" -crf 28 -preset fast "${1%.*}_compressed.mp4"; }
# Multi-stream (requires restream.io or similar, or use this with multiple RTMP)
multistream() {
local key="$1"
echo "Pipe OBS to: rtmp://localhost/live/$key"
echo "Configure OBS Custom RTMP: rtmp://localhost/live"
}
# ─────────────────────────────────────────────────────────────────────────────
# Apple Development
# ─────────────────────────────────────────────────────────────────────────────
alias xc='~/.local/bin/xc'
alias app='~/.local/bin/app'
alias sim='xc sim'
alias simboot='xc sim boot'
alias simlog='xc sim log'
alias dd='xc derived-data'
alias ddclean='xc derived-data clean'
# Quick Xcode project open
xopen() { open -a Xcode "${1:-.}"; }
# Swift REPL with common imports
alias swiftr='swift repl'
alias swift-sh='swift -e'
# Instruments/profiling
alias instr='xcrun xctrace record --template'
alias leaks-check='leaks --atExit --'
# ─────────────────────────────────────────────────────────────────────────────
# Godot Development
# ─────────────────────────────────────────────────────────────────────────────
# Editor with LSP enabled (for external editor support)
alias godot-lsp='godot --editor --lsp-port 6005'
# Headless operations (CI/build server)
alias godot-export='godot --headless --export-release'
alias godot-export-debug='godot --headless --export-debug'
alias godot-import='godot --headless --import'
# Run project
alias godot-run='godot --path . --'
alias godot-debug='godot --path . --debug --'
alias godot-scene='godot --path . --scene'
# GDScript tools
alias gdf='gdformat'
alias gdl='gdlint'
alias gdfix='gdformat -i'
# Format all GDScript in project
gdfmt() { fd -e gd | xargs gdformat -i; }
gdcheck() { fd -e gd | xargs gdlint; }
# ─────────────────────────────────────────────────────────────────────────────
# Android Development
# ─────────────────────────────────────────────────────────────────────────────
export ANDROID_HOME=~/Library/Android/sdk
path=($ANDROID_HOME/cmdline-tools/latest/bin $ANDROID_HOME/platform-tools $ANDROID_HOME/emulator $path)
# SDK management (prefer CLI over Android Studio GUI)
alias sdkm='sdkmanager'
alias sdkl='sdkmanager --list'
alias sdku='sdkmanager --update'
alias avdm='avdmanager'
alias avdl='avdmanager list avd'
# ADB shortcuts
alias adbd='adb devices'
alias adbr='adb reverse tcp:8081 tcp:8081' # React Native
alias adblog='adb logcat -v time'
alias adbi='adb install'
alias adbclear='adb shell pm clear'
alias adbuninstall='adb uninstall'
# Emulator
alias emu='emulator -list-avds'
emul() { emulator -avd "${1:-$(emulator -list-avds | head -1)}" & }
# Gradle (use wrapper)
alias gw='./gradlew'
alias gwb='./gradlew build'
alias gwc='./gradlew clean'
alias gwa='./gradlew assembleDebug'
alias gwi='./gradlew installDebug'
alias gwt='./gradlew test'
alias gwl='./gradlew lint'
# ─────────────────────────────────────────────────────────────────────────────
# Automagic
# ─────────────────────────────────────────────────────────────────────────────
alias proj='~/.local/bin/proj'
alias meeting='~/.local/bin/meeting'
alias seccheck='~/.local/bin/seccheck'
alias devenv='~/.local/bin/dev-env'
alias wake='~/.local/bin/wake'
alias autoclean='~/.local/bin/autoclean'
# GitHub Actions Runner
alias ghr='~/actions-runner/scripts/runner-status.sh'
alias ghr-start='launchctl load ~/Library/LaunchAgents/com.user.github-runner.plist'
alias ghr-stop='launchctl unload ~/Library/LaunchAgents/com.user.github-runner.plist'
alias ghr-restart='ghr-stop && sleep 2 && ghr-start'
alias ghr-update='~/actions-runner/scripts/update-runner.sh'
alias ghr-logs='tail -f ~/actions-runner/_diag/runner.stdout.log'
# ─────────────────────────────────────────────────────────────────────────────
# Greeting + Wake (background, non-blocking)
# ─────────────────────────────────────────────────────────────────────────────
[[ -o interactive && ! -f /tmp/.greeted-$(date +%Y%m%d) ]] && {
~/.local/bin/greet 2>/dev/null &!
~/.local/bin/wake 2>/dev/null &!
touch /tmp/.greeted-$(date +%Y%m%d)
}
# Syntax highlighting (must be last)
source "$(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"