-
Notifications
You must be signed in to change notification settings - Fork 7
/
zshrc
374 lines (284 loc) · 8.93 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
# ============================================================================
# Path {{{
# ============================================================================
path=(
"./.git/safe/../../bin"
"./.git/safe/../../bin/stubs"
"$HOME/.local/bin"
"$HOME/.stack/bin"
"$HOME/.asdf/bin"
"$HOME/.asdf/shims"
"/usr/local/bin"
"/usr/local/sbin"
"/Applications/Postgres.app/Contents/Versions/latest/bin"
"$HOME/Library/Android/sdk/platform-tools"
"/usr/bin"
"/bin"
"/usr/sbin"
"/sbin"
)
eval "$(/opt/homebrew/bin/brew shellenv)"
export XDG_CONFIG_HOME="$HOME/.config"
# }}}
# ============================================================================
# Options {{{
# ============================================================================
# Try to correct misspelled commands
setopt CORRECT
# Require exit or logout to exit a shell
setopt IGNORE_EOF
# Treat the ‘#’, ‘~’ and ‘^’ characters as part of patterns for filename
# generation
setopt EXTENDED_GLOB
# }}}
# ============================================================================
# Functions {{{
# ============================================================================
# Built in version of mv that can handle patterns
autoload zmv
# Create a directory and then cd into it
mcd() {
mkdir -p "$@" && cd "$@" || exit 1
}
# }}}
# ============================================================================
# Editor {{{
# ============================================================================
export VISUAL='nvim'
export EDITOR="$VISUAL"
# }}}
# ============================================================================
# Aliases {{{
# ============================================================================
# ======
# GLOBAL
# ======
# All of a sudden, everything is hilarious
alias -g poop=pop
# fucking seriously
alias -g 0a=-a
# ===
# ZSH
# ===
alias reload!='. ~/.zshrc'
alias :q='exit'
# =======
# UTILITY
# =======
# Search for a process and kill it but in a funny way
# `fucking phoenix`
alias fucking="pkill -9 -f"
# Mark a git repo as being safe
alias mksafe="mkdir .git/safe"
# ===
# GIT
# ===
alias g=git
# alias straight to difftool for quick access
alias gdiff='git diff'
# quick aliases for common actions
alias ga='git add'
alias gc!='git c'
alias gcm='git cm'
alias gco='git co'
alias gp='git push'
alias gmf='git merge --ff-only'
alias gup='git up'
alias gsup='git sup'
alias gbc='git create-branch'
alias gbd='git delete-branch'
# log aliases
alias gl='git l'
alias glb='git lb'
# ======
# EDITOR
# ======
alias e=nvim
# =====
# XCODE
# =====
# Clear the derived data folder cause uuuuuuggggghhhhhhh
alias fuxcode='rm -rf ~/Library/Developer/Xcode/DerivedData/'
# =====
# TOOLS
# =====
# Use eza instead of ls
alias ls='eza --icons=always'
# Automatically install binstubs with bundler
b(){
if [[ $# == 0 ]]; then
(bundle check > /dev/null || bundle install) && \
bundle binstubs --all --path=./bin/stubs
else
bundle "$@"
fi
}
# }}}
# ============================================================================
# Completion {{{
# ============================================================================
# fish-like autocomplete suggestions
source "$(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
bindkey '^y' autosuggest-accept
fpath=(~/.config/zsh/completion-scripts $fpath)
# Add custom completion for git-delete-branch based on branch names
_git_delete_branch() {
__gitcomp_nl "$(__git_heads)"
}
autoload -U compinit && compinit
autoload -U bashcompinit && bashcompinit
# matches case insensitive for lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# pasting with tabs doesn't perform completion
zstyle ':completion:*' insert-tab pending
# }}}
# ============================================================================
# History {{{
# ============================================================================
HISTFILE=~/.zsh_history
HISTSIZE=10000000
SAVEHIST=$HISTSIZE
# share history between sessions ???
setopt SHARE_HISTORY
# add timestamps to history
setopt EXTENDED_HISTORY
# adds history incrementally
setopt INC_APPEND_HISTORY
# don't record dupes in history
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_REDUCE_BLANKS
# }}}
# ============================================================================
# Navigation {{{
# ============================================================================
setopt auto_cd
cdpath=($HOME $PROJECTS $PROJECTS/gfontenot $PROJECTS/Square/Cash)
# Configure Terminal to open new tabs in the current directory
precmd () {print -Pn "\e]2; %~/ \a"}
preexec () {print -Pn "\e]2; %~/ \a"}
# Function to perform when we change directories
function chpwd() {
emulate -LR zsh
# Auto ls when cding into a directory
ls
}
# }}}
# ============================================================================
# Appearance {{{
# ============================================================================
# Use colors for CLI commands (like ls)
export CLICOLOR=true
# ======
# PROMPT
# ======
autoload -U colors && colors
setopt prompt_subst
export PROMPT='%(?.%F{green}.%F{red})❯%f '
export RPROMPT=$'%c $(prompt_git_info)'
prompt_git_info() {
if prompt_git_dir &>/dev/null; then
echo "$(prompt_current_branch)$(prompt_rebase_info)$(prompt_repo_dirty)$(prompt_needs_push)$(prompt_current_sha)"
fi
}
prompt_current_branch() {
local branch_name="$(prompt_current_branch_name)"
if [ "$branch_name" = "HEAD" ]; then
echo "%{$fg[red]%}DETACHED%{$reset_color%}"
else
echo "%{$fg[blue]%}$branch_name%{$reset_color%}"
fi
}
prompt_current_sha() {
echo " %{$fg[yellow]%}$(git rev-parse --short HEAD 2>/dev/null)%{$reset_color%}"
}
prompt_rebase_info() {
local git_dir="$(prompt_git_dir)"
if [ -f "$git_dir/BISECT_LOG" ]; then
echo "+bisect"
elif [ -f "$git_dir/MERGE_HEAD" ]; then
echo "+merge"
else
for file in rebase rebase-apply rebase-merge; do
if [ -e "$git_dir/$file" ]; then
echo "+rebase"
break
fi
done
fi
}
prompt_repo_dirty() {
if [[ ! $(git status 2>/dev/null) =~ "working tree clean" ]]; then
echo " %{$fg[red]%}✗%{$reset_color%}"
fi
}
prompt_needs_push() {
if [[ -n "$(git cherry -v origin/$(prompt_current_branch_name) 2>/dev/null)" ]]; then
echo " %{$fg[red]%}⬆%{$reset_color%}"
fi
}
prompt_current_branch_name() {
git rev-parse --abbrev-ref HEAD 2>/dev/null
}
prompt_git_dir() {
git rev-parse --git-dir 2>/dev/null
}
# }}}
# ============================================================================
# FZF {{{
# ============================================================================
source <(fzf --zsh)
export FZF_DEFAULT_OPTS='
--bind ctrl-u:page-up,ctrl-f:page-down
--color=dark
--color=fg:-1,bg:-1,hl:#c678dd,fg+:#ffffff,bg+:#4b5263,hl+:#d858fe
--color=info:#98c379,prompt:#61afef,pointer:#be5046,marker:#e5c07b,spinner:#61afef,header:#61afef
'
# Use fd and eza (with previews) instead of find and ls
eza_preview="eza --tree --color=always {} | head -200"
bat_preview="bat -n --color=always --line-range :500 {}"
show_file_or_dir_preview="if [ -d {} ]; then $eza_preview; else $bat_preview; fi"
export FZF_DEFAULT_COMMAND="fd --hidden --strip-cwd-prefix --exclude .git"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS="--preview '$show_file_or_dir_preview'"
export FZF_ALT_C_COMMAND="fd --type=d --hidden --strip-cwd-prefix --exclude .git"
export FZF_ALT_C_OPTS="--preview '$eza_preview'"
# Advanced customization of fzf options via _fzf_comprun function
# - The first argument to the function is the name of the command.
# - You should make sure to pass the rest of the arguments to fzf.
_fzf_comprun() {
local command=$1
shift
case "$command" in
cd) fzf --preview "$eza_preview" "$@" ;;
export|unset) fzf --preview "eval 'echo ${}'" "$@" ;;
ssh) fzf --preview 'dig {}' "$@" ;;
*) fzf --preview "$show_file_or_dir_preview" "$@" ;;
esac
}
# Use fd to generate the list for path completion
_fzf_compgen_path() {
fd --hidden --exclude .git . "$1"
}
# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
fd --type=d --hidden --exclude .git . "$1"
}
# }}}
# ============================================================================
# SSH {{{
# ============================================================================
export SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh
# }}}
# ============================================================================
# JAVA {{{
# ============================================================================
export JAVA_HOME=$(unset JAVA_HOME; /usr/libexec/java_home -v 17)
export PATH=$PATH:$JAVA_HOME
# }}}
# ============================================================================
# Misc {{{
# ============================================================================
# Private config that shouldn't be shared
if [ -f "$HOME/.config/zsh/private.zsh" ]; then
source "$HOME/.config/zsh/private.zsh"
fi