-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
266 lines (219 loc) · 7.17 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
# zmodload zsh/zprof
if [[ $TERM == xterm-256color && -n $TMUX ]]; then
export TERM=tmux-256color
fi
# export RUST_BACKTRACE=1
export ZVM_INSTALL="$HOME/.zvm/self"
export TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/plugin-cache"
mkdir -p $TF_PLUGIN_CACHE_DIR
export PATH="$HOME/code/me/aud/out:$PATH"
export PATH="$HOME/.scripts:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.zvm/bin:$PATH"
export PATH="$HOME/.local/go/bin:$PATH"
export PATH="$HOME/go/bin:$PATH"
export PATH="$ZVM_INSTALL/:$PATH"
export HISTFILE=~/.zsh_history
export HISTSIZE=10000
export SAVEHIST=10000
setopt inc_append_history
# setopt share_history
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
setopt globdots
# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
export VISUAL='vim'
else
export EDITOR='nvim'
export VISUAL='nvim'
fi
[ -s "$HOME/.cargo/env" ] && \. "$HOME/.cargo/env"
[ -s "$HOME/.snc-env" ] && \. "$HOME/.snc-env"
[ -s "$HOME/.creds" ] && \. "$HOME/.creds"
# -----------------------------
# zinit
# -----------------------------
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
source "${ZINIT_HOME}/zinit.zsh"
fpath=( ~/.zfunc "${fpath[@]}" )
if type brew &>/dev/null; then
# this may be required before running the next commands
# sudo chmod -R 755 $(brew --prefix)
#
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
else
fpath=(~/.zsh/completions $fpath)
fi
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /usr/bin/terraform terraform
complete -C aws_completer aws
zcompdump="${XDG_CACHE_HOME:-$HOME/.cache}/zcompdump"
if [[ ! -f $zcompdump || $ZSH_COMPDUMP_CHANGED -eq 1 ]]; then
compinit -C -d $zcompdump
else
compinit -d $zcompdump
fi
zinit light romkatv/powerlevel10k
zinit light Aloxaf/fzf-tab
zinit ice depth"1";
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-autosuggestions
zinit light unixorn/fzf-zsh-plugin
install_precommit_hooks() {
if [ -f .pre-commit-config.yaml ] && ! [ -f .git/hooks/pre-commit ]; then
echo "pre-commit config found. Installing hooks..."
pre-commit install
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd install_precommit_hooks
# -----------------------------
# lazy env loaders
# -----------------------------
if command -v nvm >/dev/null 2>&1; then
load_nvm() {
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
}
nvm() {
unset -f nvm
load_nvm
nvm "$@"
}
use_nvm_version() {
if [ -f .nvmrc ]; then
nvm use 2>/dev/null || {
nvm install && nvm use;
}
fi
}
add-zsh-hook chpwd use_nvm_version
fi
if command -v pyenv >/dev/null 2>&1; then
load_pyenv() {
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
}
pyenv() {
unset -f pyenv
load_pyenv
pyenv "$@"
}
fi
# -----------------------------
# aliases
# -----------------------------
alias tree="tree -C"
alias l="eza -lam --icons=auto"
alias ll="eza -lamhUuH --icons=auto --git"
alias t="eza -a -T -L 2 --icons=auto"
alias dotfiles='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
alias j='just'
alias jl='just --list --unsorted'
alias ai='llm -m claude-3.5-sonnet'
alias nvsql="nvim '+SQLua'"
alias whattheme='~/.scripts/xctl theme'
delta() { command delta --$(whattheme) "$@" }
bat() { command bat --theme=gruvbox-$(whattheme) "$@" }
btm() {
local theme="gruvbox" # default is dark
if [[ $(whattheme) == "light" ]]; then theme="nord-light"; fi
command btm --enable_gpu --theme="$theme" "$@"
}
watch() { command watch --color "$@" }
checkrs() {
cargo clippy --all-features --all-targets -- -D warnings
cargo deny --log-level error check advisories bans sources
cargo machete
}
we() {
local filter_flag=""
local zparseopts_return
zparseopts -D -E -a zparseopts_return f:=filter_flag
if (( ${#filter_flag} == 1 )); then
filter_flag="-f=${ignore_flag[1]}"
fi
if (( ${#zparseopts_return} > 0 )); then
echo "Usage: we [-f=\"FILTER_PATTERN\"] 'command [ARG]...'"
return 1
fi
local cmd="${1}"
if [[ -z "$cmd" ]]; then
echo "Please provide a command to run with we."
return 1
fi
watchexec -c -r -w . $filter_flag -- $cmd
}
nv() {
if [[ -d $1 ]]; then
cd "$1"
command nvim
else
command nvim "$@"
fi
}
# -----------------------------
# zstyle
# -----------------------------
# Bindings and Widgets
function clear-screen-and-scrollback() { clear && printf '\e[3J' && zle reset-prompt }
zle -N clear-screen-and-scrollback
# don't go into vim-mode if we're already in vim
if [[ -z "$VIMRUNTIME" ]]; then
bindkey -v
fi
# bind the clear to B so that i don't accidentally press it when using a vim motion
bindkey '^B' clear-screen-and-scrollback
bindkey '^Z' autosuggest-accept
# bindkey '^X' autosuggest-execute
bindkey '^P' history-beginning-search-backward
bindkey '^N' history-beginning-search-forward
bindkey -v
bindkey '^[' vi-cmd-mode # ESC to enter normal mode
# block/beam cursor in normal/insert mode
function zle-keymap-select {
if [[ ${KEYMAP} == vicmd ]] ||
[[ $1 = 'block' ]]; then
echo -ne '\e[1 q' # Block cursor in normal mode
else
echo -ne '\e[5 q' # Beam cursor in insert mode
fi
}
zle -N zle-keymap-select
# Set default cursor to beam on shell startup
echo -ne '\e[5 q'
# FZF config
export FZF_DEFAULT_OPTS='--height 100% --layout=reverse --no-mouse'
export FZF_DEFAULT_COMMAND='rg --hidden -l ""'
zstyle ':completion:complete:*:options' sort false
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# fzf-preview for windowed view with fzf-tab : https://github.com/Aloxaf/fzf-tab/wiki/Preview
# zstyle ':fzf-tab:complete:*:*' fzf-preview \
# 'eza -T -L 1 --icons --color=always $realpath'
zstyle ':fzf-tab:complete:git-(a|add|diff|restore):*' fzf-preview \
'git diff $word | delta'
zstyle ':fzf-tab:complete:systemctl-*:*' fzf-preview \
'SYSTEMD_COLORS=1 systemctl status $word'
zstyle ':fzf-tab:complete:*:*' fzf-preview \
'if test -f $realpath; then; bat --color=always $realpath; else; eza -a -T -L 1 --icons --color=always $realpath; fi'
command -v direnv >/dev/null 2>&1 && eval "$(direnv hook zsh)"
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# eval "$(starship init zsh)"
# zprof