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