.zshrc
1# zmodload zsh/zprof
2# =============================================================================
3# ZSH Configuration
4# =============================================================================
5
6# -----------------------------------------------------------------------------
7# 1. Homebrew
8# -----------------------------------------------------------------------------
9if [[ -f "/opt/homebrew/bin/brew" ]]; then
10 eval "$(/opt/homebrew/bin/brew shellenv)"
11fi
12
13# -----------------------------------------------------------------------------
14# 2. PATH additions (check if directories exist before adding)
15# -----------------------------------------------------------------------------
16typeset -U path # Ensure unique entries in PATH
17
18# Local binaries (mise, etc.)
19[[ -d "$HOME/.local/bin" ]] && path=("$HOME/.local/bin" $path)
20
21# Package managers
22[[ -d "$HOME/Library/pnpm" ]] && export PNPM_HOME="$HOME/Library/pnpm" && path=("$PNPM_HOME" $path)
23[[ -d "$HOME/.bun/bin" ]] && export BUN_INSTALL="$HOME/.bun" && path=("$BUN_INSTALL/bin" $path)
24
25# Optional tools
26# [[ -d "$HOME/.pkl" ]] && path=("$HOME/.pkl" $path)
27# [[ -d "$HOME/.git-ai/bin" ]] && path=("$HOME/.git-ai/bin" $path)
28# [[ -d "$HOME/.npm-global/bin" ]] && path=("$HOME/.npm-global/bin" $path)
29# [[ -d "$HOME/.opencode/bin" ]] && path=("$HOME/.opencode/bin" $path)
30
31export GPG_TTY=$(tty)
32
33# -----------------------------------------------------------------------------
34# 3. Environment Variables
35# -----------------------------------------------------------------------------
36export EDITOR="zed"
37export VISUAL="$EDITOR"
38export LANG="${LANG:-en_US.UTF-8}"
39
40# History
41export HIST_STAMPS="yyyy-mm-dd"
42export HISTSIZE=50000
43export SAVEHIST=50000
44export HISTFILE="${HISTFILE:-$HOME/.zsh_history}" # Explicit histfile
45setopt HIST_VERIFY # Show command before executing from history
46setopt HIST_REDUCE_BLANKS # Remove superfluous blanks
47setopt INC_APPEND_HISTORY # Write immediately, not on shell exit
48setopt EXTENDED_HISTORY
49setopt HIST_EXPIRE_DUPS_FIRST
50setopt HIST_IGNORE_DUPS
51setopt HIST_IGNORE_SPACE
52setopt SHARE_HISTORY
53
54# Quality of Life
55setopt AUTO_CD # cd by typing directory name
56setopt AUTO_PUSHD # Push dirs onto stack automatically
57setopt PUSHD_IGNORE_DUPS # Don't push duplicates
58setopt INTERACTIVE_COMMENTS # Allow comments in interactive shell
59setopt NO_BEEP # Disable beep on error
60
61# FZF
62export FZF_DEFAULT_OPTS="--height 40% --layout=reverse --border --color=border:grey --color=query:cyan"
63
64# Lazy-load API keys on first use
65function __load_api_keys() {
66 export OLLAMA_API_KEY=$(security find-generic-password -a $USER -s ollama_api_key -w 2>/dev/null)
67 export OPENROUTER_API_KEY=$(security find-generic-password -a $USER -s openrouter_api_key -w 2>/dev/null)
68 export OPENCODE_API_KEY=$(security find-generic-password -a $USER -s opencode_api_key -w 2>/dev/null)
69 export RESEND_API_KEY=$(security find-generic-password -a $USER -s resend_api_key -w 2>/dev/null)
70 unfunction __load_api_keys 2>/dev/null
71}
72
73# POP
74export POP_FROM=jacob@dalamb.me
75export POP_SIGNATURE="Sent with [Pop](https://github.com/charmbracelet/pop)!"
76
77# -----------------------------------------------------------------------------
78# 4. Oh My Zsh
79# -----------------------------------------------------------------------------
80export ZSH="$HOME/.oh-my-zsh"
81
82# Settings (must be before sourcing oh-my-zsh)
83zstyle ':omz:update' mode auto
84zstyle ':omz:plugins:alias-finder' autoload yes
85zstyle ':omz:plugins:keychain' agents gpg
86
87DISABLE_AUTO_TITLE="true"
88ENABLE_CORRECTION="true"
89COMPLETION_WAITING_DOTS="true"
90
91# Plugins
92plugins=(
93 aliases
94 brew
95 bun
96 command-not-found
97 eza
98 fzf
99 gh
100 git
101 git-commit
102 history
103 httpie
104 isodate
105 macos
106 node
107 npm
108 python
109 sudo
110 zsh-autosuggestions
111)
112
113source "$ZSH/oh-my-zsh.sh"
114
115# -----------------------------------------------------------------------------
116# 5. Tool Initializations (after oh-my-zsh)
117# -----------------------------------------------------------------------------
118(( $+commands[starship] )) && cache_eval "starship" "starship init zsh"
119(( $+commands[zoxide] )) && cache_eval "zoxide" "zoxide init zsh"
120(( $+commands[fixit] )) && cache_eval "fixit" "fixit init zsh"
121[[ -f "$HOME/.atuin/bin/env" ]] && . "$HOME/.atuin/bin/env"
122(( $+commands[atuin] )) && cache_eval "atuin" "atuin init zsh"
123(( $+commands[mole] )) && cache_eval "mole" "mole completion zsh"
124[[ -s "$HOME/.bun/_bun" ]] && source "$HOME/.bun/_bun"
125
126# -----------------------------------------------------------------------------
127# 6. Aliases
128# -----------------------------------------------------------------------------
129alias pn='pnpm'
130alias nu='/opt/homebrew/bin/nu'
131
132# -----------------------------------------------------------------------------
133# 7. Local/Private Configuration (always last)
134# -----------------------------------------------------------------------------
135[[ -f "$HOME/.env.secrets" ]] && source "$HOME/.env.secrets"
136[[ -f "$HOME/.zshrc.local" ]] && source "$HOME/.zshrc.local"
137# At the end, before local config
138# __load_api_keys
139# zprof