-
Notifications
You must be signed in to change notification settings - Fork 1
/
zshrc
451 lines (352 loc) · 11.5 KB
/
zshrc
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
#zmodload zsh/zprof
##########
# 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
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 nvim config
alias ez='vi ~/.zshrc'
alias sz='source ~/.zshrc'
#fzf
alias ea='nvim $(fzf --preview="cat {}")'
#alias fkf ='nvim $(fzf --preview="cat {}")'
#vi $(fzf --preview='cat {}')
#nvim $(fzf --preview='cat {}')
# git
alias gst='git status'
alias gaa='git add -A'
alias gc='git commit'
alias gcm='git checkout trunk'
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 .....='../../../..'
# 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 rr='cargo run --release'
##########
# FUNCTIONS
##########
mkdircd() {
mkdir -p $1 && cd $1
}
spinner() {
while
do
for i in "-" "\\" "|" "/"
do
echo -n " $i \r\r"
sleep .1
done
done
}
# 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
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%}"
}
# 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)'
simple_prompt() {
local prompt_color="%B"
export PROMPT="%{$prompt_color%}$promptnormal"
}
#########
# PROMPT
#########
setopt prompt_subst
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%}"
}
# 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)'
simple_prompt() {
local prompt_color="%B"
export PROMPT="%{$prompt_color%}$promptnormal"
}
########
# ENV
########
export COLOR_PROFILE="dark"
case $OSTYPE in
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 vi="nvim"
export EDITOR="nvim"
export PSQL_EDITOR="nvim -c"set filetype=sql""
export GIT_EDITOR="nvim"
else
export EDITOR='vi'
export PSQL_EDITOR='vi -c"set filetype=sql"'
export GIT_EDITOR='vi'
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
# 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
# direnv
if type direnv &> /dev/null; then
eval "$(direnv hook zsh)"
fi
export PATH=$PATH:/Users/blouse_man/go/bin
alias vi="nvim"
# bun completions
[ -s "/Users/blouse_man/.bun/_bun" ] && source "/Users/blouse_man/.bun/_bun"
# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
PQ_LIB_DIR="$(brew --prefix libpq)/lib"
# Generated for envman. Do not edit.
[ -s "$HOME/.config/envman/load.sh" ] && source "$HOME/.config/envman/load.sh"
#export JAVA_HOME=$(/usr/libexec/java_home)
#export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
#export JAVA_HOME=$(/usr/libexec/java_home -v 11)
#export JAVA_HOME=$(/usr/libexec/java_home -v 22)
export PATH=$JAVA_HOME/bin:$PATH
export ANDROID_HOME=/Users/blouse_man/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator
# pnpm
export PNPM_HOME="/Users/blouse_man/Library/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end
#
#
export PATH=$PATH:/opt/homebrew/bin
#zprof
# BEGIN opam configuration
# This is useful if you're using opam as it adds:
# - the correct directories to the PATH
# - auto-completion for the opam binary
# This section can be safely removed at any time if needed.
[[ ! -r '/Users/blouse_man/.opam/opam-init/init.zsh' ]] || source '/Users/blouse_man/.opam/opam-init/init.zsh' > /dev/null 2> /dev/null
# END opam configuration
source <(fzf --zsh)
export GPG_TTY=$(tty) # or /Users/blouse_man/.bashrc if you use bash