-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzshrc
More file actions
371 lines (310 loc) · 10.5 KB
/
Copy pathzshrc
File metadata and controls
371 lines (310 loc) · 10.5 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
# -*- sh -*-
[ -s "$HOME/.pre.zsh" ] && source "$HOME/.pre.zsh"
# Unset CONFIG_DIR to avoid conflicts with lazygit (set by shadowenv)
unset CONFIG_DIR
CONFIG_DIR=dotfiles
export ZSH_DISABLE_COMPFIX=true
export GIT_COMPLETION_CHECKOUT_NO_GUESS=true
export ZSH_DISABLE_COMPFIX=true
skip_global_compinit=1
export ZSH=$HOME/.oh-my-zsh
export FZF_CTRL_T_OPTS="--ansi --preview '(bat {} --color always || highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 1> /dev/null | head -400'"
export FZF_DEFAULT_COMMAND='fd --color=always --type f'
export FZF_DEFAULT_OPTS='--height 90% --border'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export ZSH_THEME=""
export HYPHEN_INSENSITIVE="true"
export UPDATE_ZSH_DAYS=1
export DISABLE_AUTO_TITLE="true"
export DISABLE_AUTO_UPDATE="true"
export DISABLE_UPDATE_PROMPT=true
export DISABLE_COMPFIX="true"
export ENABLE_CORRECTION="true"
export COMPLETION_WAITING_DOTS="false"
export DISABLE_UNTRACKED_FILES_DIRTY="true"
export ZSH_AUTOSUGGEST_STRATEGY=(history completion)
export HISTSIZE=1000000000
export SAVEHIST=$HISTSIZE
setopt EXTENDED_HISTORY
export SHELL="/bin/zsh"
export TERM='xterm-256color'
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_TYPE=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export GPG_TTY=$(tty)
export SDKMAN_DIR="$HOME/.sdkman"
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export FZF_COMPLETION_TRIGGER=":"
export FZF_COMPLETION_DIR_COMMANDS="cd rmdir tree git gt"
export EDITOR="nvim"
export ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE="50"
export ZSH_AUTOSUGGEST_HISTORY_IGNORE="?(#c51,)"
export ZSH_AUTOSUGGEST_USE_ASYNC=1
export ZSH_HIGHLIGHT_MAXLENGTH=50
export BUN_INSTALL="$HOME/.bun"
plugins=(git gitfast tmux zsh-autosuggestions history-substring-search last-working-dir extract fzf-tab zsh-syntax-highlighting)
GENCOMPL_PY=python3
source $ZSH/oh-my-zsh.sh
source "$HOME/$CONFIG_DIR/zsh-completion-generator.plugin.zsh"
source "$HOME/$CONFIG_DIR/paste_hell.zsh"
source "$HOME/$CONFIG_DIR/completion.zsh"
source "$HOME/$CONFIG_DIR/key-bindings.zsh"
zstyle :plugin:zsh-completion-generator programs rg bat
setopt shwordsplit
setopt HIST_IGNORE_ALL_DUPS
zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}"
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path $HOME/.zsh/cache
setopt EXTENDEDGLOB
bindkey '^[^P' history-substring-search-up
bindkey '^[^N' history-substring-search-down
bindkey '^ ' autosuggest-accept
[[ -x /opt/homebrew/bin/brew ]] && eval $(/opt/homebrew/bin/brew shellenv)
[[ -x /home/linuxbrew/.linuxbrew/bin/brew ]] && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
path_dirs=(
"/usr/local/sbin"
"/usr/local/bin"
"/usr/sbin"
"/usr/bin"
"/sbin"
"/bin"
"$HOME/.cargo/bin"
"$HOME/.rust/bin"
"$HOME/src/git-fuzzy/bin"
"$HOME/tools"
"$HOME/bin"
"$HOME/$CONFIG_DIR/scripts"
"$HOME/.rbenv/bin/"
"$HOME/.emacs.d/bin/"
"$HOME/.config/emacs.d/bin/"
"$HOME/Library/Python/3.9/bin"
"$HOME/.fzf/bin"
"$HOME/.local/bin"
"/home/linuxbrew/.linuxbrew/bin"
"$HOME/node_modules/.bin/"
"$HOME/.opencode/bin"
"$BUN_INSTALL/bin"
"$HOME/go/bin"
)
for dir in "${path_dirs[@]}"; do
[ -s "$dir" ] && export PATH="$dir:$PATH"
done
[ -s "/usr/local/bin/nvim" ] && export EDITOR="/usr/local/bin/nvim"
[ -s "/usr/bin/nvim" ] && export EDITOR="/usr/bin/nvim"
alias vi=nvim
alias vim=nvim
alias l="lsd -A1tlrh --blocks size,date,name"
alias gfz="git fuzzy"
alias cat="bat"
alias gll='git log --graph --pretty="format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --abbrev-commit'
alias grsh="git reset --hard"
alias c="cursor ."
alias multipull="find . -mindepth 1 -maxdepth 1 -type d -print -exec git -C {} pull \;"
alias tree="lsd --tree"
alias mig="DISABLE_SPRING=1 bin/rails db:migrate db:test:prepare"
alias myprs='gh pr list -S '\''is:open is:pr author:@me archived:false'\'
alias clean_clipboard="pbpaste | sed 's#\\n#\n#g' | pbcopy"
alias dt="dev test"
alias force-remote='git fetch origin $(git rev-parse --abbrev-ref HEAD) && git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)'
alias clean-local-branches='git branch --merged | grep -v main | grep -v master | xargs git branch --delete'
if command -v gt &> /dev/null; then
alias rebase-remote-main='gco main && git pull && gco - && gt restack && gt submit'
fi
alias my-branches="git branch --list 'phaselockedloop*'"
alias wt="cdworktree"
alias bbat="bat --paging=never --plain --color always"
alias gcom="git checkout main"
# Graphite
if command -v gt &> /dev/null; then
alias gs="gt status"
alias gco="gt checkout"
alias gca="gt create"
alias gm="gt modify --all"
fi
gbb() {
git show --format='%C(auto)%D %s' -s $(git for-each-ref --sort=committerdate --format='%(refname:short)' refs/heads/)
}
delete-branches() {
branches=$(git branch --format='%(refname:short)' |
grep --invert-match '\*')
selected_branches=$(echo "$branches" | fzf --multi --preview="git log --no-merges --color --stat -p {}")
for branch in $selected_branches
do
git branch --delete --force "$branch"
done
}
rgl() {
rg -B5 -A5 -g "*.rb" -g"!*test*" -p "$1" | less
}
rglc() {
rg -B5 -A5 -g "*.rb" -g"!*test*" -p "$1" "$2" | less
}
rglt() {
rg -g "*.rb" -p "$1" | less
}
fpath=($ZSH/'completions' $fpath)
autoload -U promptinit; promptinit
if [ -x "$(command -v zoxide)" ]; then
eval "$(zoxide init zsh)"
fi
if whence -v vivid > /dev/null 2>&1; then
export LS_COLORS="$(vivid --color-mode 8-bit generate molokai)"
export ZLS_COLORS=$LS_COLORS
fi
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
enable-fzf-tab
function _fzf_complete_dt() {
_fzf_complete --prompt="test:" -- "$@" < <(
fd -t f -p "_test.rb" components/*/test
)
}
unalias ga 2>/dev/null
unalias gr 2>/dev/null
function ga() { git add "$@" }
function gr() { git restore --staged "$@" }
_git_fzf_complete() {
if [[ "$LBUFFER" =~ ^ga[[:space:]]+ ]]; then
local files=$(git diff --relative --name-only | fzf --multi --preview 'git diff --color=always -- {}' --preview-window=right:60%:wrap)
if [[ -n "$files" ]]; then
LBUFFER="${LBUFFER}${files//$'\n'/ }"
zle accept-line
else
zle redisplay
fi
elif [[ "$LBUFFER" =~ ^gr[[:space:]]+ ]]; then
local files=$(git diff --cached --relative --name-only | fzf --multi --preview 'git diff --cached --color=always -- {}' --preview-window=right:60%:wrap)
if [[ -n "$files" ]]; then
LBUFFER="${LBUFFER}${files//$'\n'/ }"
zle accept-line
else
zle redisplay
fi
else
zle fzf-tab-complete
fi
}
zle -N _git_fzf_complete
bindkey '^I' _git_fzf_complete
function _fzf_compgen_path() {
rg --files --glob "!.git" . "$1"
}
function _fzf_compgen_dir() {
fd --color always --type d --hidden --follow --exclude ".git" . "$1"
}
# Function to navigate directories using fzf and fd
cd_fzf_full() {
local current_dir=$(pwd)
local paths=()
local parent_paths=()
# Populate with every parent directory
# But exclude current directory and root directory
# Put newlines between parent paths so FZF works
while [[ "$current_dir" != "/" ]]; do
parent_paths+=($current_dir$'\n')
current_dir=$(dirname "$current_dir")
done
parent_paths=("${parent_paths[@]:1:${#parent_paths[@]}-1}")
# Get directories by depth, limited to 50 total
local nested_dirs=""
local count=0
local depth=1
while [[ $count -lt 50 ]]; do
# Get directories at current depth and make paths relative to current directory
local dirs_at_depth=$(fd --type d --exclude ".git" --exclude "target/release" --max-depth $depth --min-depth $depth . "$(pwd)" | \
while read -r dir; do
echo "${dir#$(pwd)/}"
done | head -n $((50 - count)))
if [[ -z "$dirs_at_depth" ]]; then
break
fi
nested_dirs+=$dirs_at_depth$'\n'
count=$((count + $(echo "$dirs_at_depth" | wc -l)))
depth=$((depth + 1))
done
local all_dirs=$(printf "%s\n%s" "${parent_paths[@]}" "$nested_dirs" | sed '/^$/d' | sort -r)
local selected_dir=$(echo "$all_dirs" | fzf --tac)
if [[ -n "$selected_dir" ]]; then
cd "$selected_dir"
fi
zle reset-prompt # Refresh prompt to reflect new directory
}
# Create a zle widget
zle -N cd_fzf_full_widget cd_fzf_full
# Bind Control-o to the above widget
bindkey "^o" cd_fzf_full_widget
# Make a widget for zoxide interactive
zoxide_query_interactive() {
local selected_dir=$(zoxide query --interactive)
if [[ -n "$selected_dir" ]]; then
cd "$selected_dir"
fi
zle reset-prompt # Refresh prompt to reflect new directory
}
zle -N zoxide_query_interactive_widget zoxide_query_interactive
# Bind control-i to zoxide interactive
bindkey "^u" zoxide_query_interactive_widget
# Sources
source_if_exists=(
"$HOME/bin/fzf-git.sh"
"$HOME/.bun/_bun"
"$ZSH/completions/_bun"
"$HOME/.sdkman/bin/sdkman-init.sh"
"$HOME/.post.zsh"
)
for file in "${source_if_exists[@]}"; do
[ -s "$file" ] && source "$file"
done
typeset -U fpath
autoload -U +X bashcompinit && bashcompinit
autoload -Uz compinit
if [ "$(date +'%j')" != "$(stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null)" ]; then
compinit
else
compinit -C
fi
if command -v gt &> /dev/null; then
#compdef gt
###-begin-gt-completions-###
#
# yargs command completion script
#
# Installation: gt completion >> ~/.zshrc
# or gt completion >> ~/.zprofile on OSX.
#
_gt_yargs_completions()
{
local reply
local si=$IFS
IFS=$'
' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" gt --get-yargs-completions "${words[@]}"))
IFS=$si
_describe 'values' reply
}
compdef _gt_yargs_completions gt
###-end-gt-completions-###
fi
function cdworktree() {
# Get the root git directory
local git_root=$(git rev-parse --git-common-dir 2>/dev/null)
if [[ -z "$git_root" ]]; then
echo "Not in a git repository"
return 1
fi
# Remove .git from the end if present
git_root=${git_root%.git}
# Get list of worktrees and change directory
local selected_dir=$(git worktree list |
fzf --height 40% --reverse --header="Select a worktree" |
awk '{print $1}')
if [[ -n "$selected_dir" ]]; then
cd "${selected_dir}"
# Print current directory for confirmation
echo "Changed to: $(pwd)"
fi
}
correct_ignore=(claude)
eval "$(starship init zsh)"
export PATH=$PATH:/usr/local/go/bin