zsh/dot-zshrc 6.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/go/bin"
96
path_add "$HOME/.cargo/bin"
97
path_add "$HOME/.local/share/go/bin"
98
path_add "$HOME/.local/bin"
99
path_add "/usr/local/bin"
100
path_add "$HOME/.bun/bin"
101
path_add "/Applications/Docker.app/Contents/Resources/bin"
102
path_add "$HOME/.tmux/plugins/t-smart-tmux-session-manager/bin"
103
path_add "$HOME/.deno/bin"
104
path_add "$HOME/.foundry/bin"
105
path_add "$HOME/.local/share"
106
path_add "$HOME/.local/share/solana/install/active_release/bin"
107
path_add "$HOME/.aztec/bin"
108
path_add "$HOME/.nargo/bin"
109
path_add "$HOME/.helios/bin"
110
path_add "$HOME/.radicle/bin"
111
path_add "$PNPM_HOME"
112
113
export PATH
114
115
# fnm (node version manager)
116
if command -v fnm >/dev/null 2>&1; then
117
  eval "$(fnm env --shell zsh)"
118
  path_add "$FNM_MULTISHELL_PATH/bin"
119
  export PATH
120
  # auto-switch node version on cd when .node-version / .nvmrc present
121
  __fnm_autouse() {
122
    if [ -f .node-version ] || [ -f .nvmrc ]; then
123
      fnm use --silent-if-unchanged 2>/dev/null
124
    fi
125
  }
126
  autoload -Uz add-zsh-hook
127
  add-zsh-hook precmd __fnm_autouse
128
fi
129
130
# cargo
131
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
132
133
# =============================================================================
134
# Aliases
135
# =============================================================================
136
alias ls='eza --icons=always'
137
alias ll='eza -l --icons=always'
138
alias la='eza -a --icons=always'
139
alias lg='lazygit'
140
alias nf='neofetch'
141
alias fl='fastfetch -c ~/.config/fastfetch/presets/examples/8.jsonc'
142
alias ff='fastfetch -c ~/.config/fastfetch/presets/examples/20.jsonc'
143
alias nvimrc='nvim ~/.config/nvim'
144
alias shitter='ssh itter'
145
# alias tailscale='/Applications/Tailscale.app/Contents/MacOS/Tailscale'
146
alias ai='aichat'
147
alias system='macchina'
148
alias bonsai='cbonsai -li -t 0.4'
149
alias lst='lstr --icons --color=always --size'
150
alias keys='keysmasher'
151
alias timestamp='node -e "process.stdout.write(new Date().toISOString())"'
152
alias cleardns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'
153
alias t='sesh picker'
154
155
# -------------------------------------------
156
# Suffix Aliases - Open Files by Extension
157
# -------------------------------------------
158
# Just type the filename to open it with the associated program
159
alias -s json=jless
160
alias -s md=bat
161
alias -s go='$EDITOR'
162
alias -s rs='$EDITOR'
163
alias -s txt=bat
164
alias -s log=bat
165
alias -s py='$EDITOR'
166
alias -s js='$EDITOR'
167
alias -s ts='$EDITOR'
168
alias -s html=open  # macOS: open in default browser
169
170
# =============================================================================
171
# Functions
172
# =============================================================================
173
174
# Fuzzy-find a file and open in nvim
175
nvimf() {
176
  local file
177
  file=$(fd --type f --hidden --exclude .git | fzf --preview "bat --color=always {}")
178
  if [ -z "$file" ]; then
179
    echo "No file selected"
180
  else
181
    nvim "$file"
182
  fi
183
}
184
185
# Install a tree-sitter parser into the nvim luarocks tree
186
tsi() {
187
  local parser="$1"
188
  local tree="$HOME/.local/share/nvim/site"
189
  luarocks --lua-version=5.1 "--tree=$tree" install "tree-sitter-$parser"
190
}
191
192
# nvim startup time -> grep summary line
193
ns() {
194
  rm -f ~/.nvim-startup.txt
195
  nvim --headless --startuptime ~/.nvim-startup.txt +qa
196
  grep "NVIM STARTED" ~/.nvim-startup.txt
197
}
198
199
# nvim startup time -> full bat dump
200
nh() {
201
  rm -f ~/.nvim-startup.txt
202
  nvim --headless --startuptime ~/.nvim-startup.txt +qa
203
  bat ~/.nvim-startup.txt
204
}
205
206
# Copy file contents to clipboard
207
cpf() {
208
  cat "$1" | wl-copy
209
  echo "✔︎ Copied to clipboard!"
210
}
211
212
# UTC timestamp for blog frontmatter
213
blogdate() {
214
  date -u +"%Y-%m-%dT%H:%M:%SZ"
215
}
216
217
# =============================================================================
218
# Completion
219
# =============================================================================
220
autoload -Uz compinit
221
compinit
222
223
# =============================================================================
224
# Tooling init
225
# =============================================================================
226
command -v zoxide >/dev/null 2>&1 && eval "$(zoxide init zsh)"
227
command -v starship >/dev/null 2>&1 && eval "$(starship init zsh)"
228
command -v fzf >/dev/null 2>&1 && eval "$(fzf --zsh)"
229
230
# zsh-autosuggestions and syntax highlighting
231
source $HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
232
source $HOME/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
233
export PATH="$HOME/.local/bin:$PATH"
234
235
# bun completions
236
[ -s "/home/stevedylandev/.bun/_bun" ] && source "/home/stevedylandev/.bun/_bun"
237
238
# bun
239
export BUN_INSTALL="$HOME/.bun"
240
export PATH="$BUN_INSTALL/bin:$PATH"
241
242
# fnm
243
FNM_PATH="/home/stevedylandev/.local/share/fnm"
244
if [ -d "$FNM_PATH" ]; then
245
  export PATH="$FNM_PATH:$PATH"
246
  eval "$(fnm env --shell zsh)"
247
fi
248
export NO_AT_BRIDGE=1 # stops GTK apps relaunching it