zsh/dot-zshrc 7.3 K raw
1
# ~/.zshrc — mirrors the nushell config
2
#
3
# Linked via: fling link -s zsh -l ~
4
5
# Interactive-only guard
6
case $- in
7
  *i*) ;;
8
  *) return ;;
9
esac
10
11
# =============================================================================
12
# History
13
# =============================================================================
14
HISTFILE="$HOME/.zsh_history"
15
HISTSIZE=10000
16
SAVEHIST=10000
17
setopt EXTENDED_HISTORY
18
setopt HIST_IGNORE_ALL_DUPS   # ~ HISTCONTROL=ignoredups
19
setopt HIST_IGNORE_SPACE      # ~ HISTCONTROL=ignorespace
20
setopt HIST_REDUCE_BLANKS
21
setopt APPEND_HISTORY         # ~ shopt -s histappend
22
setopt INC_APPEND_HISTORY
23
setopt share_history
24
setopt hist_verify
25
26
27
# vi mode (matches nushell edit_mode: vi)
28
set -o vi
29
30
# Edit command in $EDITOR
31
autoload -Uz edit-command-line
32
zle -N edit-command-line
33
bindkey '^O' edit-command-line
34
35
# =============================================================================
36
# Environment
37
# =============================================================================
38
export EDITOR="nvim"
39
export CLICOLOR=1
40
41
# Go
42
export GOPATH="$HOME/.local/share/go"
43
export GOMODCACHE="$HOME/.local/share/go-mod-cache"
44
45
# bat
46
export BAT_THEME="ansi"
47
export BAT_THEME_DARK="ansi"
48
49
# gpg
50
export GPG_TTY="$(tty)"
51
52
# misc
53
export BULLETS_FEEDS="feeds.stevedylan.dev/feed.xml"
54
55
# pnpm
56
export PNPM_HOME="$HOME/Library/pnpm"
57
58
# fzf
59
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude ".git"'
60
export FZF_DEFAULT_OPTS='
61
  --color=fg:8:bold,fg+:15,bg:-1,bg+:-1
62
  --color=hl:10:bold,hl+:10:bold
63
  --color=info:8,spinner:9,header:4
64
  --color=prompt:2,pointer:9,marker:1
65
  --color=border:7,label:15:bold,query:15
66
  --border="rounded"
67
  --border-label=""
68
  --preview-window="border-rounded"
69
  --prompt="> "
70
  --marker=" "
71
  --pointer="◆"
72
  --separator=""
73
  --scrollbar=""
74
  --gutter=" "
75
  --info=inline-right'
76
77
# =============================================================================
78
# PATH
79
# =============================================================================
80
# path_add <dir>: prepend if not already present and dir exists
81
path_add() {
82
  case ":$PATH:" in
83
    *":$1:"*) ;;
84
    *) [ -d "$1" ] && PATH="$1:$PATH" ;;
85
  esac
86
}
87
88
path_add "/opt/homebrew/bin"
89
path_add "/usr/local/go/bin"
90
path_add "$HOME/.cargo/bin"
91
path_add "$HOME/.local/share/go/bin"
92
path_add "$HOME/.local/bin"
93
path_add "/usr/local/bin"
94
path_add "$HOME/.bun/bin"
95
path_add "/Applications/Docker.app/Contents/Resources/bin"
96
path_add "$HOME/.tmux/plugins/t-smart-tmux-session-manager/bin"
97
path_add "$HOME/.deno/bin"
98
path_add "$HOME/.foundry/bin"
99
path_add "$HOME/.local/share"
100
path_add "$HOME/.local/share/solana/install/active_release/bin"
101
path_add "$HOME/.aztec/bin"
102
path_add "$HOME/.nargo/bin"
103
path_add "$HOME/.helios/bin"
104
path_add "$HOME/.radicle/bin"
105
path_add "$PNPM_HOME"
106
107
export PATH
108
109
# fnm (node version manager)
110
if command -v fnm >/dev/null 2>&1; then
111
  eval "$(fnm env --shell zsh)"
112
  path_add "$FNM_MULTISHELL_PATH/bin"
113
  export PATH
114
  # auto-switch node version on cd when .node-version / .nvmrc present
115
  __fnm_autouse() {
116
    if [ -f .node-version ] || [ -f .nvmrc ]; then
117
      fnm use --silent-if-unchanged 2>/dev/null
118
    fi
119
  }
120
  autoload -Uz add-zsh-hook
121
  add-zsh-hook precmd __fnm_autouse
122
fi
123
124
# cargo
125
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
126
127
# =============================================================================
128
# Aliases
129
# =============================================================================
130
alias ls='eza --icons=always'
131
alias ll='eza -l --icons=always'
132
alias la='eza -a --icons=always'
133
alias lg='lazygit'
134
alias nf='neofetch'
135
alias fl='fastfetch -c ~/.config/fastfetch/presets/examples/8.jsonc'
136
alias ff='fastfetch -c ~/.config/fastfetch/presets/examples/20.jsonc'
137
alias nvimrc='nvim ~/.config/nvim'
138
alias shitter='ssh itter'
139
# alias tailscale='/Applications/Tailscale.app/Contents/MacOS/Tailscale'
140
alias ai='aichat'
141
alias system='macchina'
142
alias bonsai='cbonsai -li -t 0.4'
143
alias lst='lstr --icons --color=always --size'
144
alias keys='keysmasher'
145
alias timestamp='node -e "process.stdout.write(new Date().toISOString())"'
146
alias cleardns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'
147
148
# -------------------------------------------
149
# Suffix Aliases - Open Files by Extension
150
# -------------------------------------------
151
# Just type the filename to open it with the associated program
152
alias -s json=jless
153
alias -s md=bat
154
alias -s go='$EDITOR'
155
alias -s rs='$EDITOR'
156
alias -s txt=bat
157
alias -s log=bat
158
alias -s py='$EDITOR'
159
alias -s js='$EDITOR'
160
alias -s ts='$EDITOR'
161
alias -s html=open  # macOS: open in default browser
162
163
# =============================================================================
164
# Functions
165
# =============================================================================
166
# Open a sesh session via gum filter
167
t() {
168
  local selected
169
  selected=$(sesh list -i | gum filter --limit 1 --placeholder "Choose a session" --height 50 --prompt="> " --indicator.foreground="2" --match.foreground="2")
170
  if [ -z "$selected" ]; then
171
    echo "No session selected"
172
  else
173
    sesh connect "$selected"
174
  fi
175
}
176
177
# Fuzzy-find a file and open in nvim
178
nvimf() {
179
  local file
180
  file=$(fd --type f --hidden --exclude .git | fzf --preview "bat --color=always {}")
181
  if [ -z "$file" ]; then
182
    echo "No file selected"
183
  else
184
    nvim "$file"
185
  fi
186
}
187
188
# Install a tree-sitter parser into the nvim luarocks tree
189
tsi() {
190
  local parser="$1"
191
  local tree="$HOME/.local/share/nvim/site"
192
  luarocks --lua-version=5.1 "--tree=$tree" install "tree-sitter-$parser"
193
}
194
195
# nvim startup time -> grep summary line
196
ns() {
197
  rm -f ~/.nvim-startup.txt
198
  nvim --headless --startuptime ~/.nvim-startup.txt +qa
199
  grep "NVIM STARTED" ~/.nvim-startup.txt
200
}
201
202
# nvim startup time -> full bat dump
203
nh() {
204
  rm -f ~/.nvim-startup.txt
205
  nvim --headless --startuptime ~/.nvim-startup.txt +qa
206
  bat ~/.nvim-startup.txt
207
}
208
209
# Copy file contents to clipboard
210
cpf() {
211
  cat "$1" | pbcopy
212
  echo "✔︎ Copied to clipboard!"
213
}
214
215
# Set orbiter key to personal
216
orbiter-personal() {
217
  gum spin --spinner dot --spinner.foreground="2" --title "Updating..." -- orbiter auth --key "$(op read 'op://Personal/orbiter-api-key/credential')"
218
  local check
219
  check=$(gum style --foreground="2" "✓ ")
220
  gum join "$check" "Orbiter key set to personal!"
221
}
222
223
# Set orbiter key to orbiter account
224
orbiter-account() {
225
  gum spin --spinner dot --spinner.foreground="2" --title "Updating..." -- orbiter auth --key "$(op read 'op://Personal/orbiter-account-api-key/credential')"
226
  local check
227
  check=$(gum style --foreground="2" "✓ ")
228
  gum join "$check" "Orbiter key set to Orbiter account!"
229
}
230
231
# UTC timestamp for blog frontmatter
232
blogdate() {
233
  date -u +"%Y-%m-%dT%H:%M:%SZ"
234
}
235
236
# =============================================================================
237
# Completion
238
# =============================================================================
239
autoload -Uz compinit
240
compinit
241
242
# =============================================================================
243
# Tooling init
244
# =============================================================================
245
command -v zoxide >/dev/null 2>&1 && eval "$(zoxide init zsh)"
246
command -v starship >/dev/null 2>&1 && eval "$(starship init zsh)"
247
command -v fzf >/dev/null 2>&1 && eval "$(fzf --zsh)"
248
249
# zsh-autosuggestions and syntax highlighting
250
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
251
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
252
export PATH="$HOME/.local/bin:$PATH"