-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathzshrc
More file actions
593 lines (487 loc) · 15.2 KB
/
zshrc
File metadata and controls
593 lines (487 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
##############
# BASIC SETUP
##############
typeset -U PATH
autoload colors; colors;
#############
## PRIVATE ##
#############
# Include private stuff that's not supposed to show up
# in the dotfiles repo
local private="${HOME}/.zsh.d/private.sh"
if [ -e ${private} ]; then
. ${private}
fi
##########
# HISTORY
##########
HISTFILE=$HOME/.zsh_history
HISTSIZE=50000
SAVEHIST=50000
setopt INC_APPEND_HISTORY # Immediately append to history file.
setopt EXTENDED_HISTORY # Record timestamp in history.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS # Dont record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Dont record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Dont write duplicate entries in the history file.
setopt SHARE_HISTORY # Share history between all sessions.
unsetopt HIST_VERIFY # Execute commands using history (e.g.: using !$) immediately
#############
# COMPLETION
#############
# Add completions installed through Homebrew packages
# See: https://docs.brew.sh/Shell-Completion
if type brew &>/dev/null; then
FPATH=/usr/local/share/zsh/site-functions:$FPATH
fi
# Speed up completion init, see: https://gist.github.com/ctechols/ca1035271ad134841284
autoload -Uz compinit
for dump in ~/.zcompdump(N.mh+24); do
compinit
done
compinit -C
# unsetopt menucomplete
unsetopt flowcontrol
setopt auto_menu
setopt complete_in_word
setopt always_to_end
setopt auto_pushd
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
###############
# KEY BINDINGS
###############
# Vim Keybindings
bindkey -v
# This is a "fix" for zsh in Ghostty:
# Ghostty implements the fixterms specification https://www.leonerd.org.uk/hacks/fixterms/
# and under that `Ctrl-[` doesn't send escape but `ESC [91;5u`.
#
# (tmux and Neovim both handle 91;5u correctly, but raw zsh inside Ghostty doesn't)
#
# Thanks to @rockorager for this!
bindkey "^[[91;5u" vi-cmd-mode
# Open line in Vim by pressing 'v' in Command-Mode
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# Push current line to buffer stack, return to PS1
bindkey "^Q" push-input
# Make up/down arrow put the cursor at the end of the line
# instead of using the vi-mode mappings for these keys
bindkey "\eOA" up-line-or-history
bindkey "\eOB" down-line-or-history
bindkey "\eOC" forward-char
bindkey "\eOD" backward-char
# CTRL-R to search through history
bindkey '^R' history-incremental-search-backward
# CTRL-S to search forward in history
bindkey '^S' history-incremental-search-forward
# Accept the presented search result
bindkey '^Y' accept-search
# Use the arrow keys to search forward/backward through the history,
# using the first word of what's typed in as search word
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward
# Use the same keys as bash for history forward/backward: Ctrl+N/Ctrl+P
bindkey '^P' history-search-backward
bindkey '^N' history-search-forward
# Backspace working the way it should
bindkey '^?' backward-delete-char
bindkey '^[[3~' delete-char
# Some emacs keybindings won't hurt nobody
bindkey '^A' beginning-of-line
bindkey '^E' end-of-line
# Where should I put you?
bindkey -s '^F' "tmux-sessionizer\n"
#########
# Aliases
#########
case $OSTYPE in
linux*)
local aliasfile="${HOME}/.zsh.d/aliases.Linux.sh"
[[ -e ${aliasfile} ]] && source ${aliasfile}
;;
darwin*)
local aliasfile="${HOME}/.zsh.d/aliases.Darwin.sh"
[[ -e ${aliasfile} ]] && source ${aliasfile}
;;
esac
if type lsd &> /dev/null; then
alias ls=lsd
fi
alias lls='ls -lh --sort=size --reverse'
alias llt='ls -lrt'
alias bear='clear && echo "Clear as a bear!"'
alias history='history 1'
alias hs='history | grep '
# Use rsync with ssh and show progress
alias rsyncssh='rsync -Pr --rsh=ssh'
# Edit/Source vim config
alias ez='vim ~/.zshrc'
alias sz='source ~/.zshrc'
# git
alias monsterclean='git clean -fdx -e .jj/'
alias gst='git status'
alias s='git status'
alias gaa='git add -A'
alias gc='git commit'
alias gcm='git checkout main'
alias gd='git diff'
alias gdc='git diff --cached'
# [c]heck [o]ut
alias co='git checkout'
# [f]uzzy check[o]ut
fo() {
git branch --no-color --sort=-committerdate --format='%(refname:short)' | fzf --header 'git checkout' | xargs git checkout
}
# [p]ull request check[o]ut
po() {
gh pr list --author "@me" | fzf --header 'checkout PR' | awk '{print $(NF-5)}' | xargs git checkout
}
alias up='git push'
alias upf='git push --force'
alias pu='git pull'
alias pur='git pull --rebase'
alias fe='git fetch'
alias re='git rebase'
alias lr='git l -30'
alias cdr='cd $(git rev-parse --show-toplevel)' # cd to git Root
alias hs='git rev-parse --short HEAD'
alias hm='git log --format=%B -n 1 HEAD'
# tmux
alias tma='tmux attach -t'
alias tmn='tmux new -s'
alias tmm='tmux new -s main'
# ceedee dot dot dot
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
# Notes
alias n='vim +Notes' # Opens Vim and calls `:Notes`
# Go
alias got='go test ./...'
alias k='kubectl'
alias -g withcolors="| sed '/PASS/s//$(printf "\033[32mPASS\033[0m")/' | sed '/FAIL/s//$(printf "\033[31mFAIL\033[0m")/'"
alias zedn='/Applications/Zed\ Nightly.app/Contents/MacOS/cli'
alias r='cargo run'
alias cr='cargo run'
alias rr='cargo run --release'
alias p='pnpm'
alias pd='pnpm dev'
alias pc='pnpm check'
alias pf='pnpm check:fix'
alias pt='pnpm test --run'
alias cli='pnpm -C cli cli'
alias ap='amp'
alias -g DLOG='RUST_LOG=debug,cranelift_codegen=error,h2=error,hyper_util=error,wasmtime=error,globset=error'
# jj aliases
# Most of that stuff is taken from here: https://x.com/dimfeld/status/1926863685487559038
# Workflow:
# jj commit
# jjub
# jj git push
# Get the closest ancestor bookmark
alias jjpb="jj log -r 'latest(heads(ancestors(@) & bookmarks()), 1)' --limit 1 --no-graph --ignore-working-copy -T bookmarks | tr -d '*'"
# jj update branch
jj-update-branch() {
REV=${1:-@}
if [ $# -gt 0 ]; then
shift
fi
jj bookmark move $(jjpb) --to "$REV" "$@"
}
alias jjub=jj-update-branch
alias jn='jj new'
alias jc='jj commit'
alias js='jj status'
alias jf='jj git fetch'
alias jp='jj git push'
alias jd='jj diff'
alias jrt='jj retrunk'
alias jjl="jj log"
jjlt() {
local n="${1:-10}"
jj log -r "latest(ancestors(trunk()), $n)" --color=always -T '
change_id.shortest(8) ++ " " ++
commit_id.shortest(8) ++ " " ++
"§" ++ author.email() ++ "§{" ++
committer.timestamp().ago() ++ "{" ++
if(bookmarks, bookmarks ++ " ", "") ++
description.first_line()
' | column -t -s '{' | perl -pe '
BEGIN {
# Bright colors that work on dark backgrounds
@colors = (1,2,3,5,6,9,10,11,12,13,14,33,39,41,47,50,51,82,118,154,166,172,196,199,208,214,220,226);
sub colorize {
my $e = shift;
$e =~ s/\e\[[0-9;]*m//g;
my $h = 0;
$h += ord($_) for split("", $e);
my $c = $colors[$h % scalar(@colors)];
return "\e[38;5;${c}m$e\e[0m";
}
}
s/§([^§]+)§/colorize($1)/ge
' | less -XFRS
}
alias jl="jj log"
alias jlr="jj lr"
##########
# FUNCTIONS
##########
mkdircd() {
mkdir -p $1 && cd $1
}
render_dot() {
local out="${1}.png"
dot "${1}" \
-Tpng \
-Nfontname='JetBrains Mono' \
-Nfontsize=10 \
-Nfontcolor='#fbf1c7' \
-Ncolor='#fbf1c7' \
-Efontname='JetBrains Mono' \
-Efontcolor='#fbf1c7' \
-Efontsize=10 \
-Ecolor='#fbf1c7' \
-Gbgcolor='#1d2021' > ${out} && \
kitty +kitten icat --align=left ${out}
}
beautiful() {
while
do
i=$((i + 1)) && echo -en "\x1b[3$(($i % 7))mo" && sleep .2
done
}
spinner() {
while
do
for i in "-" "\\" "|" "/"
do
echo -n " $i \r\r"
sleep .1
done
done
}
s3() {
local route="s3.thorstenball.com/${1}"
aws s3 cp ${1} s3://${route}
echo http://${route} | pbcopy
}
# Toggle between git and jj prompt modes
prompt_git_mode() {
export VCS_PROMPT_MODE="git"
echo "Switched to git prompt mode"
}
prompt_jj_mode() {
unset VCS_PROMPT_MODE
echo "Switched to jj prompt mode (default)"
}
# Open PR on GitHub
pr() {
if type gh &> /dev/null; then
gh pr view -w
else
echo "gh is not installed"
fi
}
#########
# PROMPT
#########
setopt prompt_subst
# Kinda replaced by `vcs_prompt_info` while I experiment with `jj`
git_prompt_info() {
local dirstatus=" OK"
local dirty="%{$fg_bold[red]%} X%{$reset_color%}"
if [[ ! -z $(git status --porcelain 2> /dev/null | tail -n1) ]]; then
dirstatus=$dirty
fi
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo " %{$fg_bold[green]%}${ref#refs/heads/}$dirstatus%{$reset_color%}"
}
jj_prompt_info() {
local dirty="%{$fg_bold[red]%} X%{$reset_color%}"
local clean=""
local conflicts="%{$fg_bold[yellow]%} !%{$reset_color%}"
# Get bookmark and change info
local bookmark=$(jj log -r @ --no-graph -T 'bookmarks' 2> /dev/null | tr -d '*' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
local change_id=$(jj log -r @ --no-graph -T 'change_id.shortest()' 2> /dev/null) || return
# Check working copy status
local wc_status=""
if jj status | grep -q "Working copy changes:"; then
wc_status=$dirty
elif jj log -r @ --no-graph -T 'conflict' 2> /dev/null | grep -q "true"; then
wc_status=$conflicts
else
wc_status=$clean
fi
# Show bookmark if exists, otherwise change ID
local ref_display="${bookmark:-$change_id}"
echo " %{$fg_bold[green]%}${ref_display}${wc_status}%{$reset_color%}"
}
vcs_prompt_info() {
local dirty="%{$fg_bold[red]%} X%{$reset_color%}"
local clean=""
# Check if we're forcing git mode
if [[ "$VCS_PROMPT_MODE" == "git" ]]; then
# Force git mode - show git info even if jj is available
local dirstatus="$clean"
if [[ ! -z $(git status --porcelain 2> /dev/null | tail -n1) ]]; then
dirstatus=$dirty
fi
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo " %{$fg_bold[green]%}${ref#refs/heads/}$dirstatus%{$reset_color%}"
return
fi
# Default behavior: check if we're in a jj repo
if command -v jj &>/dev/null && jj status &>/dev/null; then
jj_prompt_info
return
fi
# Fallback to Git
local dirstatus="$clean"
if [[ ! -z $(git status --porcelain 2> /dev/null | tail -n1) ]]; then
dirstatus=$dirty
fi
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo " %{$fg_bold[green]%}${ref#refs/heads/}$dirstatus%{$reset_color%}"
}
# local dir_info_color="$fg_bold[black]"
# This just sets the color to "bold".
# Future me. Try this to see what's correct:
# $ print -P '%fg_bold[black] black'
# $ print -P '%B%F{black} black'
# $ print -P '%B black'
local dir_info_color="%B"
local dir_info_color_file="${HOME}/.zsh.d/dir_info_color"
if [ -r ${dir_info_color_file} ]; then
source ${dir_info_color_file}
fi
local dir_info="%{$dir_info_color%}%(5~|%-1~/.../%2~|%4~)%{$reset_color%}"
local promptnormal="φ %{$reset_color%}"
local promptjobs="%{$fg_bold[red]%}φ %{$reset_color%}"
# Show how many nested `nix shell`s we are in
# local nix_prompt=""
# # Set ORIG_SHLVL only if it wasn't previously set and if SHLVL > 1 and
# # GHOSTTY_RESOURCES_DIR is not empty
# if [[ -z $ORIG_SHLVL ]]; then
# if [[ -z $GHOSTTY_RESOURCES_DIR ]]; then
# export ORIG_SHLVL=$SHLVL
# elif [[ $SHLVL -gt 1 ]]; then
# export ORIG_SHLVL=$SHLVL
# fi
# fi;
# # If ORIG_SHLVL is set and SHLVL is now greater: display nesting level
# if [[ ! -z $ORIG_SHLVL && $SHLVL -gt $ORIG_SHLVL ]]; then
# nix_prompt=("(%F{yellow}$(($SHLVL - $ORIG_SHLVL))%f) ")
# fi;
# PROMPT='${dir_info}$(git_prompt_info) ${nix_prompt}%(1j.$promptjobs.$promptnormal)'
PROMPT='${dir_info}$(vcs_prompt_info) ${nix_prompt}%(1j.$promptjobs.$promptnormal)'
simple_prompt() {
local prompt_color="%B"
export PROMPT="%{$prompt_color%}$promptnormal"
}
########
# ENV
########
export COLOR_PROFILE="dark"
case $OSTYPE in
linux*)
local envfile="${HOME}/.zsh.d/env.Linux.sh"
[[ -e ${envfile} ]] && source ${envfile}
;;
darwin*)
local envfile="${HOME}/.zsh.d/env.Darwin.sh"
[[ -e ${envfile} ]] && source ${envfile}
;;
esac
export LSCOLORS="Gxfxcxdxbxegedabagacad"
# Reduce delay for key combinations in order to change to vi mode faster
# See: http://www.johnhawthorn.com/2012/09/vi-escape-delays/
# Set it to 10ms
export KEYTIMEOUT=1
export PATH="$HOME/neovim/bin:$PATH"
if type nvim &> /dev/null; then
alias vim="nvim"
export EDITOR="nvim"
export PSQL_EDITOR="nvim -c"set filetype=sql""
export GIT_EDITOR="nvim"
else
export EDITOR='vim'
export PSQL_EDITOR='vim -c"set filetype=sql"'
export GIT_EDITOR='vim'
fi
if [[ -e "$HOME/code/clones/lua-language-server/3rd/luamake/luamake" ]]; then
alias luamake="$HOME/code/clones/lua-language-server/3rd/luamake/luamake"
fi
# rustup
export PATH="$HOME/.cargo/bin:$PATH"
# homebrew
export PATH="/usr/local/bin:$PATH"
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
# direnv
if type direnv &> /dev/null; then
eval "$(direnv hook zsh)"
fi
# mise
# if type mise &> /dev/null; then
# eval "$(mise activate zsh)"
# fi
# node.js
export NODE_PATH="/usr/local/lib/node_modules:$NODE_PATH"
# golang
export GOPATH="$HOME/code/go"
export GOBIN="$GOPATH/bin"
export PATH="$GOBIN:$PATH"
# fzf
if type fzf &> /dev/null && type rg &> /dev/null; then
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*" --glob "!vendor/*"'
export FZF_CTRL_T_COMMAND='rg --files --hidden --follow --glob "!.git/*" --glob "!vendor/*"'
export FZF_ALT_C_COMMAND="$FZF_DEFAULT_COMMAND"
fi
# Try out atuin
if type atuin &> /dev/null; then
eval "$(atuin init zsh)"
fi
# `z`
if [ -e /usr/local/etc/profile.d/z.sh ]; then
source /usr/local/etc/profile.d/z.sh
fi
if [ -e /opt/homebrew/etc/profile.d/z.sh ]; then
source /opt/homebrew/etc/profile.d/z.sh
fi
if [ -e "$HOME/.zsh.d/mkbir.zsh" ]; then
source "$HOME/.zsh.d/mkbir.zsh"
fi
# yarn
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
alias c35="llm -m claude-3.5-sonnet"
if [ -e "$HOME/.local/bin/env" ]; then
source "$HOME/.local/bin/env"
fi
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/mrnugget/bin/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/mrnugget/bin/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/mrnugget/bin/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/mrnugget/bin/google-cloud-sdk/completion.zsh.inc'; fi
# pnpm
export PNPM_HOME="/Users/mrnugget/Library/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end
export PATH=/Users/mrnugget/.opencode/bin:$PATH
export PATH="$PATH:/Users/mrnugget/.lmstudio/bin"
# Export my personal ~/bin as last one to have highest precedence
export PATH="$HOME/bin:$PATH"
# bun completions
[ -s "/Users/mrnugget/.bun/_bun" ] && source "/Users/mrnugget/.bun/_bun"
# Added by Antigravity
export PATH="/Users/mrnugget/.antigravity/antigravity/bin:$PATH"
# browser
export PATH="/Users/mrnugget/.browser/bin:$PATH"