Skip to content

Instantly share code, notes, and snippets.

@akunzai
Last active September 25, 2026 06:59
Show Gist options
  • Select an option

  • Save akunzai/616796de59282c8bfdae3005511c588e to your computer and use it in GitHub Desktop.

Select an option

Save akunzai/616796de59282c8bfdae3005511c588e to your computer and use it in GitHub Desktop.
My ZSH profile
## 1. HOMEBREW
# Initialize Homebrew environment
if [[ -x /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ -x /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
## 2. EXTERNAL TOOLS & SHELL INITS
# OrbStack
[[ -f "$HOME/.orbstack/shell/init.zsh" ]] && source "$HOME/.orbstack/shell/init.zsh"
# Zed Editor
if [[ -z "$VISUAL" ]] && command -v zed &>/dev/null; then
export VISUAL='zed --wait'
fi
## 3. PATH SETUP (ADDITIONAL SDKs & GUI TOOLS)
# Append GUI/Tool paths (auto-deduplicated via ~/.zshenv's typeset -U)
path+=(
$HOME/.dotnet/tools(N)
"$HOME/Library/Application Support/JetBrains/Toolbox/scripts"(N)
$HOME/Library/Android/sdk/platform-tools(N)
)
## SYSTEM & LOCALIZATION
export CLICOLOR=1
export LANG=en_US.UTF-8
# Prevents creation of '._*' metadata files in tar archives on macOS
export COPYFILE_DISABLE=1
## .NET
export DOTNET_CLI_UI_LANGUAGE='en-us'
export DOTNET_ENVIRONMENT=Development
export ASPNETCORE_ENVIRONMENT=Development
## GitLab CLI
export GLAB_SEND_TELEMETRY=false
## XDG LOCAL BIN
# Ensure Coding Agents can read local binaries
XDG_BIN_HOME=${XDG_BIN_HOME:-$HOME/.local/bin}
[[ -d "$XDG_BIN_HOME" ]] && export PATH="$XDG_BIN_HOME:$PATH"
# Ensure Coding Agents / Non-interactive shells can read environment variables from mise
if [[ $- != *i* ]]; then
# Ensure Homebrew path is available
if [[ -d "/opt/homebrew/bin" ]] && [[ ":$PATH:" != *":/opt/homebrew/bin:"* ]]; then
export PATH="/opt/homebrew/bin:$PATH"
fi
if [[ -d "/usr/local/bin" ]] && [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
export PATH="/usr/local/bin:$PATH"
fi
# Load dev tools and environment variables from mise
if command -v mise &>/dev/null; then
eval "$(mise hook-env -s zsh)"
fi
fi
## GO
[[ -d "$HOME/go/bin" ]] && export PATH="$PATH:$HOME/go/bin"
## RUST
[[ -f "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env"
## LM Studio
[[ -d "$HOME/.lmstudio/bin" ]] && export PATH="$PATH:$HOME/.lmstudio/bin"
# MTPLX
[[ -d "$HOME/.mtplx/bin" ]] && export PATH="$HOME/.mtplx/bin:$PATH"
## Dory
[[ -d "$HOME/.dory/bin" ]] && export PATH="$PATH:$HOME/.dory/bin"
## CLAUDE CODE CLI
export CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY=1
export CLAUDE_CODE_NO_FLICKER=1
## SSH AGENT
# Pin SSH_AUTH_SOCK to a fixed path so EVERY shell — including the non-interactive
# ones coding agents spawn, and tmux panes that outlive an SSH reconnect — reaches
# the same long-lived agent. This decouples commit signing from the per-session
# agent that sshd forwards (its socket dies when that SSH session ends, which is
# why signing broke after a reconnect). Self-heal: start the agent and load the key
# from the macOS keychain (UseKeychain stored the passphrase) if the socket is gone.
export SSH_AUTH_SOCK="$HOME/.ssh/agent.sock"
# Self-heal: verify the agent is reachable AND holds the key, not just that the
# socket file exists. A stale socket or empty agent makes git fall back to the
# encrypted private key, which prompts for the passphrase on every signature
# (ssh-keygen -Y sign ignores UseKeychain). ssh-add -l exit: 0=has key, 1=empty, 2=dead.
# --apple-use-keychain needs to reach the Security Server, which refuses
# interaction from a non-Aqua session (e.g. an incoming SSH login) with
# errSecInteractionNotAllowed (-25308 / 0xffff9d24). Skip it over SSH so a
# dead/empty agent fails loudly with guidance instead of surfacing that raw
# error mid `git commit` signing. (git pull/push over HTTPS goes through a
# separate credential helper, not this agent.)
ssh-add -l >/dev/null 2>&1
case $? in
0) ;;
1)
if [[ -z "$SSH_CONNECTION" ]]; then
ssh-add --apple-use-keychain >/dev/null 2>&1 </dev/null
elif [[ -o interactive ]]; then
print -u2 "ssh-agent: key not loaded; can't reach Keychain over SSH (Security Server interaction not allowed), run: ssh-add ~/.ssh/id_ed25519"
fi
;;
*)
rm -f "$SSH_AUTH_SOCK"
ssh-agent -a "$SSH_AUTH_SOCK" >/dev/null 2>&1
if [[ -z "$SSH_CONNECTION" ]]; then
ssh-add --apple-use-keychain >/dev/null 2>&1 </dev/null
elif [[ -o interactive ]]; then
print -u2 "ssh-agent: agent recreated, but can't reach Keychain over SSH, run: ssh-add ~/.ssh/id_ed25519"
fi
;;
esac
# Re-broadcast in case this shell had to recreate the agent mid-session (e.g.
# after a crash) - keeps GUI apps (Zed, Fork, ...) in sync with the socket
# that's actually alive, not just whatever the login-time LaunchAgent set.
launchctl setenv SSH_AUTH_SOCK "$SSH_AUTH_SOCK"
## PRIVATE & LOCAL ENVIRONMENT
[ -f "$HOME/.env.local" ] && source "$HOME/.env.local"
## PATH DEDUPLICATION
# Prevent duplicate paths in sub-shells
export PATH
typeset -U PATH path
## CORE TERMINAL SETTINGS
export HISTSIZE=1000000
export SAVEHIST=1000000
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_REDUCE_BLANKS
# GPG configuration for git commits
if [[ -t 0 ]] && command -v gpg-agent &>/dev/null; then
export GPG_TTY="$(tty)"
fi
# Set Default Editor
if command -v nvim &>/dev/null; then
export EDITOR=nvim
else
export EDITOR=vi
fi
# Ensure HOMEBREW_PREFIX is available
if [[ -z "$HOMEBREW_PREFIX" ]]; then
if [[ -d "/opt/homebrew" ]]; then
export HOMEBREW_PREFIX="/opt/homebrew"
elif [[ -d "/usr/local" ]]; then
export HOMEBREW_PREFIX="/usr/local"
fi
fi
## 1. COMPLETIONS FPATH SETUP (MUST BE BEFORE COMPINIT)
typeset -U fpath FPATH
[[ -n "$HOMEBREW_PREFIX" ]] && [[ -d "$HOMEBREW_PREFIX/share/zsh-completions" ]] && fpath=($HOMEBREW_PREFIX/share/zsh-completions $fpath)
[[ -d "$HOME/.zfunc" ]] && fpath=($HOME/.zfunc $fpath)
[[ -d "$HOME/.grok/completions/zsh" ]] && fpath=($HOME/.grok/completions/zsh $fpath)
[[ -d "$HOME/.grok/bin" ]] && export PATH="$HOME/.grok/bin:$PATH"
## 2. INITIALIZE COMPINIT (CALL ONCE)
autoload -Uz compinit
# Caching zcompdump (regenerate only if older than 24 hours for faster startup)
if [[ -n "$HOME/.zcompdump"(#qN.mh+24) ]]; then
compinit -i
else
compinit -C
fi
## 3. DYNAMIC COMPLETIONS & CLI INTEGRATIONS (CALL AFTER COMPINIT)
# mise
if command -v mise &>/dev/null; then
eval "$(mise activate zsh)"
fi
# fzf
if command -v fzf &>/dev/null; then
source <(fzf --zsh)
fi
# uv completion
if command -v uv &>/dev/null; then
eval "$(uv generate-shell-completion zsh)"
fi
# shellfirm
if command -v shellfirm &>/dev/null; then
eval "$(shellfirm init zsh)"
fi
# skills completion
if command -v skills &>/dev/null; then
source <(skills completion zsh)
elif [[ -x "$HOME/.local/bin/skills" ]]; then
source <($HOME/.local/bin/skills completion zsh)
fi
# bun completions
[ -s "$HOME/.bun/_bun" ] && source "$HOME/.bun/_bun"
# azure-cli completion
if command -v az &>/dev/null && [[ -n "$HOMEBREW_PREFIX" && -s "$HOMEBREW_PREFIX/etc/bash_completion.d/az" ]]; then
autoload -Uz bashcompinit && bashcompinit
source "$HOMEBREW_PREFIX/etc/bash_completion.d/az"
fi
## 4. FUNCTIONS
# Bulk Update System Packages via Homebrew
function up() {
brew update && brew upgrade -y
command -v mise &>/dev/null && mise upgrade --bump
if command -v skills &>/dev/null; then
skills update
fi
}
# Execute Git command across subdirectories containing .git
# Options:
# -r, -R, --recursive : traverse all subdirectories recursively (default is single-level)
# -d, --depth <N> : search up to N subdirectory levels
# -v, --verbose : show all repositories even if there is no output (default is quiet)
# -q, --quiet : quiet mode (default: only show repositories with changes or errors)
# -h, --help : show usage information
function rgit() {
local maxdepth=2
local verbose=false
local show_help=false
local find_opts=()
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
show_help=true
shift
;;
-r|-R|--recursive)
maxdepth=0
shift
;;
-d)
maxdepth=$(( $2 + 1 ))
shift 2
;;
--depth)
maxdepth=$(( $2 + 1 ))
shift 2
;;
--depth=*)
maxdepth=$(( ${1#*=} + 1 ))
shift
;;
-v|--verbose)
verbose=true
shift
;;
-q|--quiet)
verbose=false
shift
;;
--)
shift
break
;;
*)
break
;;
esac
done
if $show_help || [[ $# -eq 0 ]]; then
cat <<'EOF'
Usage: rgit [options] <git-command>...
Execute a Git command across subdirectories containing .git.
Options:
-r, -R, --recursive Traverse all subdirectories recursively (default is single-level)
-d, --depth <N> Search up to N subdirectory levels
-v, --verbose Show all repositories, including clean ones (default is quiet)
-q, --quiet Quiet mode (only show repositories with changes or errors; default)
-h, --help Show this help message
Examples:
rgit status -s # Check status across 1-level subdirectories (quiet)
rgit -v status -s # Check status across 1-level subdirectories (verbose)
rgit -r fetch --all # Fetch recursively across all nested subdirectories
rgit -d 2 pull # Pull across subdirectories up to 2 levels deep
EOF
return 0
fi
if [[ "$maxdepth" -gt 0 ]]; then
find_opts=(-maxdepth "$maxdepth")
fi
local -a git_dirs
git_dirs=("${(@f)$(find . "${find_opts[@]}" -type d -name '.git' 2>/dev/null | sort)}")
if [[ -z "${git_dirs[*]}" ]]; then
return 0
fi
local is_tty=false
[[ -t 1 ]] && is_tty=true
local printed_any=false
local gdir repo_dir rel_path out ret
for gdir in "${git_dirs[@]}"; do
[[ -z "$gdir" ]] && continue
repo_dir="${gdir:h}"
rel_path="${repo_dir#./}"
[[ "$rel_path" == "." ]] && rel_path="${PWD:t}"
if $verbose; then
$printed_any && echo ""
if $is_tty; then
printf "\033[1;36m==>\033[0m \033[1m%s\033[0m\n" "$rel_path"
else
printf "==> %s\n" "$rel_path"
fi
git -C "$repo_dir" "$@"
printed_any=true
else
if $is_tty; then
out=$(git -C "$repo_dir" -c color.ui=always "$@" 2>&1)
else
out=$(git -C "$repo_dir" "$@" 2>&1)
fi
ret=$?
if [[ -n "$out" || $ret -ne 0 ]]; then
$printed_any && echo ""
if $is_tty; then
printf "\033[1;36m==>\033[0m \033[1m%s\033[0m\n" "$rel_path"
else
printf "==> %s\n" "$rel_path"
fi
[[ -n "$out" ]] && printf "%s\n" "$out"
printed_any=true
fi
fi
done
}
# Link mise Java major versions to macOS JavaVirtualMachines
function jlink() {
local jvm_dir="$HOME/Library/Java/JavaVirtualMachines"
mkdir -p "$jvm_dir"
for d in ~/.local/share/mise/installs/java/<->(N-/); do
[[ -d "$d/Contents" ]] && ln -sfn "$d" "$jvm_dir/${d:t}.jdk"
done
/usr/libexec/java_home -V
}
# Switch and Check Java Version
function jver() {
if [ -n "$1" ]; then
export JAVA_HOME="$(/usr/libexec/java_home -v "$1")"
else
/usr/libexec/java_home -V
fi
java -version
}
## 5. ALIASES
if command -v eza &>/dev/null; then
alias ls="eza --icons --group-directories-first"
alias ll="eza -l --icons --sort=name"
alias lt="eza --tree --icons --level=2"
else
alias ls='ls -G'
alias ll='ls -lG'
fi
if [[ "$EDITOR" == "nvim" ]]; then
alias vi='nvim'
alias vim='nvim'
alias vimdiff='nvim -d'
fi
if command -v podman >/dev/null 2>&1 && ! command -v docker >/dev/null 2>&1; then
alias docker=podman
fi
if command -v uv &>/dev/null; then
alias python='uv run'
fi
## 6. PRIVATE & LOCAL ALIASE OR FUNCTION
[ -f "$HOME/.profile.local" ] && source "$HOME/.profile.local"
## 7. ZSH PLUGINS (MUST BE LOADED AFTER WIDGETS & BEFORE PROMPT)
if [[ -n "$HOMEBREW_PREFIX" ]]; then
[ -e "$HOMEBREW_PREFIX/share/zsh-autosuggestions/zsh-autosuggestions.zsh" ] && source "$HOMEBREW_PREFIX/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
[ -e "$HOMEBREW_PREFIX/opt/zsh-fast-syntax-highlighting/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh" ] && source "$HOMEBREW_PREFIX/opt/zsh-fast-syntax-highlighting/share/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh"
fi
## 8. PROMPT INITIALIZATION
# Loaded at the very end to prevent prompt rendering bottlenecks
if command -v starship &>/dev/null; then
STARSHIP_CONFIG=${HOME}/.config/starship.toml
eval "$(starship init zsh)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment