-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
396 lines (334 loc) · 12.6 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
# Hopefully this loads powerlevel10k theme faster
# 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
if type brew &>/dev/null; then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
autoload -Uz compinit
compinit
fi
##############################################################################
# Homebrew Configurações
##############################################################################
if [ -d "/opt/homebrew/bin" ]; then
export PATH="/opt/homebrew/bin:$PATH"
fi
if type brew &>/dev/null; then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
autoload -Uz compinit
compinit
fi
export HOMEBREW_NO_AUTO_UPDATE=1
##############################################################################
# Sourcing e Plugins
##############################################################################
autoload -U compinit && compinit
[[ -f "$HOME/.zfunctions.zsh" ]] && source "$HOME/.zfunctions.zsh"
source "$HOME"/.zaliases
source "$HOME"/.zprofile
# source "$HOME"/.zfunctions.zsh
source "$HOME"/.themes/zsh/minimalist/.p10k.zsh
source "$(brew --prefix)"/share/powerlevel10k/powerlevel10k.zsh-theme
source "$(brew --prefix)"/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source "$(brew --prefix)"/share/zsh-history-substring-search/zsh-history-substring-search.zsh
source "$(brew --prefix)"/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# homebrew completion
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
fi
##############################################################################
# Prompt & Completion
##############################################################################
autoload -U colors && colors
autoload -U compinit && compinit
unset HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND
unset HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[default]=fg=#ebdbb2,bold
ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=#fb4934
ZSH_HIGHLIGHT_STYLES[reserved-word]=fg=#fb4934,standout
ZSH_HIGHLIGHT_STYLES[alias]=fg=#fe8019,bold
ZSH_HIGHLIGHT_STYLES[builtin]=fg=#b8bb26,bold
ZSH_HIGHLIGHT_STYLES[function]=fg=#d3869b,bold
ZSH_HIGHLIGHT_STYLES[command]=fg=#83a598,bold
ZSH_HIGHLIGHT_STYLES[precommand]=fg=#fabd2f,bold
ZSH_HIGHLIGHT_STYLES[commandseparator]=fg=#fabd2f,bold
ZSH_HIGHLIGHT_STYLES[hashed-command]=fg=#b8bb26,bold
ZSH_HIGHLIGHT_STYLES[path]=fg=#8ec07c,underline
ZSH_HIGHLIGHT_STYLES[path_pathseparator]=fg=#d79921,underline
ZSH_HIGHLIGHT_STYLES[path_prefix]=fg=#b16286,underline
ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]=fg=#d79921,underline
ZSH_HIGHLIGHT_STYLES[globbing]=fg=#fabd2f,bold
ZSH_HIGHLIGHT_STYLES[history-expansion]=fg=#fabd2f,bold,underline
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=fg=#fabd2f,bold
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=fg=#d79921,bold
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=fg=#8ec07c,bold
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]=fg=#d3869b,bold
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=fg=#b16286,bold
ZSH_HIGHLIGHT_STYLES[double-quoted-argument-unclosed]=fg=#cc241d,bold
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=fg=#fabd2f,bold
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]=fg=#fe8019,bold
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]=fg=#fabd2f,bold
ZSH_HIGHLIGHT_STYLES[comment]=fg=#928374,bold
ZSH_HIGHLIGHT_STYLES[redirection]=fg=#fe8019,bold
ZSH_HIGHLIGHT_STYLES[assign]=fg=#b16286,bold
##############################################################################
# Configurações Gerais
##############################################################################
export LANG=en_US.UTF-8
export EDITOR=nvim
export VISUAL="$EDITOR"
# export PAGER="nvim -R"
export PAGER=nvimpager
export TERM="xterm-256color"
export DISABLE_AUTO_TITLE=true
export DISABLE_MAGIC_FUNCTIONS=true
# ls com cores
if [ -x /usr/bin/dircolors ]; then
if [ -r ~/.dircolors ]; then
eval "$(dircolors -b ~/.dircolors)"
else
eval "$(dircolors -b)"
fi
fi
##############################################################################
# History
##############################################################################
export HISTFILE=~/.zsh_history
export HISTFILESIZE=1000000000
export HISTSIZE=1000000000
export SAVEHIST=1000000000
# export HISTTIMEFORMAT="[%F %T] "
# export HIST_STAMPS="yyyy-mm-dd"
HISTCONTROL=ignoredups
setopt HISTIGNORESPACE
unsetopt EXTENDED_HISTORY
setopt BANG_HIST
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE # Do not record an event starting with a space.
setopt HIST_SAVE_NO_DUPS
setopt HIST_VERIFY
setopt HIST_REDUCE_BLANKS
setopt SHARE_HISTORY
setopt INC_APPEND_HISTORY
setopt IGNORE_EOF
setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack.
setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd.
setopt AUTO_PUSHD # Make cd push the old directory onto the directory stack.
setopt AUTOPARAMSLASH # tab completing directory appends a slash
# setopt AUTO_LIST
# setopt AUTO_MENU
setopt LIST_AMBIGUOUS
setopt EXTENDED_GLOB # Treat the ‘#’, ‘~’ and ‘^’ characters as part of patterns for filename generation, etc. (An initial unquoted ‘~’ always produces named directory expansion.)
setopt NO_BEEP
setopt GLOB_COMPLETE
setopt MENU_COMPLETE
setopt COMPLETE_ALIASES
setopt CASE_PATHS
setopt COMPLETE_IN_WORD
setopt PROMPT_SUBST
setopt NO_HUP
setopt NO_NOMATCH
##############################################################################
# KeyMappings
##############################################################################
bindkey -e
bindkey -e '^y' accept-search
bindkey -e '^o' autosuggest-accept
bindkey -e '^l' forward-char
bindkey -e '^e' forward-word
bindkey -e '^h' backward-char
bindkey -e '^b' backward-word
bindkey -e '^d' delete-char
bindkey -e '^0' beginning-of-line
bindkey -e '^;' end-of-line
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
bindkey -r ^M accept-search
# bindkey -e '^Y' accept-search
bindkey -r ^Y accept-line
bindkey '^[[Z' reverse-menu-complete
bindkey '^R' fzf-history-widget
autoload -z edit-command-line
zle -N edit-command-line
bindkey -e '^x' edit-command-line
autoload -U modify-current-argument
# Esc + s
_quote-previous-word-in-single() {
modify-current-argument '${(qq)${(Q)ARG}}'
zle vi-forward-blank-word
}
bindkey '^z' _quote-previous-word-in-single
zle -N _quote-previous-word-in-single
##############################################################################
# Fzf
##############################################################################
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
source <(fzf --zsh)
set rtp+= "$HOMEBREW"/fzf
export BAT_THEME="gruvbox-dark"
export FZF_DEFAULT_OPTS="--height 30 --ansi --layout=reverse --preview 'echo {} | batcat --color=always --language=bash --style=plain' --preview-window down:7:wrap"
export FZF_DEFAULT_COMMAND="fd --exclude={.git,.idea,.vscode,.sass-cache,node_modules,build} --hidden --type file --no-ignore-vcs"
export FZF_ALT_C_COMMAND='fd --follow --type d --exclude "Library/" --exclude "Music/"'
export FZF_CTRL_T_COMMAND=$FZF_DEFAULT_COMMAND
export FZF_CTRL_R_OPTS="--no-preview"
##############################################################################
# Misc
##############################################################################
# if [ -t 0 ]; then
# stty sane
# tty intr \^k
# # stty intr '^k'
# else
# stty sane
# tty intr \^k
# # stty intr '^k'
# fi
# function set_interrupt_key {
# stty intr "\^k"
# }
# add-zsh-hook precmd set_interrupt_key
# if [[ $- == *i* ]]; then
# stty intr '^k'
# fi
if [[ $- == *i* ]]; then
stty -ixon <$TTY >$TTY
function set_interrupt_key {
if [ -t 0 ]; then
stty intr "^k"
fi
}
add-zsh-hook precmd set_interrupt_key
else
stty intr "^k" 2>/dev/null || true
fi
autoload -U promptinit && promptinit
autoload -U add-zsh-hook
##############################################################################
# Packages
##############################################################################
if command -v zoxide >/dev/null 2>&1; then
eval "$(zoxide init zsh)"
fi
# ngrok
if command -v ngrok &>/dev/null; then
eval "$(ngrok completion)"
fi
if command -v thefuck >/dev/null 2>&1; then
eval "$(thefuck --alias)"
fi
##############################################################################
# Path
##############################################################################
# npm global
export NPM_PACKAGES=${HOME}/.npm-global
export NPM_CONFIG_PREFIX=${HOME}/.npm-global
export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
export PATH="$NPM_PACKAGES/bin:$PATH"
MANPATH="$NPM_PACKAGES/share/man:$MANPATH"
# Created by `pipx`
export PATH="$PATH:/Users/arthurgehrke/.local/bin"
export PYENV_ROOT="$HOME/.pyenv"
export PATH=$(pyenv root)/shims:$PATH
export PATH="/opt/homebrew/opt/rustup/bin:$PATH"
export GOPATH=$HOME/go
export PATH=$PATH:/Users/arthurgehrke/go/bin
export LDFLAGS="-L/opt/homebrew/opt/openssl/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl/lib/pkgconfig"
# rbenv (Ruby)
if command -v rbenv &>/dev/null; then
export RBENV_ROOT=~/.rbenv
eval "$(rbenv init -)"
fi
# jenv (Java)
if command -v jenv &>/dev/null; then
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init - --no-rehash)"
fi
# Composer (PHP)
if command -v composer &>/dev/null; then
export PATH="$HOME/.composer/vendor/bin:$PATH"
fi
if command -v pipenv &>/dev/null; then
eval "$(_PIPENV_COMPLETE=zsh_source pipenv)"
fi
# nodenv (Node.js)
if command -v nodenv &>/dev/null; then
export PATH="$HOME/.nodenv/bin:$PATH"
eval "$(nodenv init -)"
fi
# rye (Python)
if command -v pyenv &>/dev/null; then
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
export PATH="$HOME/.cargo/bin:$PATH"
. "$HOME/.cargo/env"
source /Users/arthurgehrke/.config/broot/launcher/bash/br
function upper() {
echo "$*" | tr '[:lower:]' '[:upper:]'
}
function lower() {
echo "$*" | tr '[:upper:]' '[:lower:]'
}
function capitalize() {
echo "$*" | tr '[:upper:]' '[:lower:]' | sed 's/^\w\|\s\w/\U&/g'
}
function cf() {
cmd=$(complete-fzf --alias="$(alias)" --command="$*")
_confirm_run "$cmd"
}
function cr() {
cmd=$(history | sed 's/\s\+[0-9]\+\s\+//g' | sort -rn | awk '!x[$0]++' | fzf --layout=reverse --prompt='Cmd> ')
_confirm_run "$cmd"
}
if [ ! -z "$MY_TERMINAL" ]; then
if [ "$MY_TERMINAL" != "alacritty" ]; then
stty -ixon
fi
fi
function irg() {
local file
local line
local RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
local INITIAL_QUERY="${*:-}"
# The preview window bit is described in the man page section for the --preview-window option but basically: ~2 is
# the top 2 lines as a fixed header, +{2} is the base scroll offset extracted from the second field, +2 is an extra
# 2 line offset to account for the header, /2 is put in the middle of the preview area
# For the color bit, -1 keeps the original color from the input
read -r file line <<<"$(
FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
fzf --ansi \
--disabled --query "$INITIAL_QUERY" \
--color "hl:-1:underline,hl+:-1:underline:reverse" \
--header='Press ? to toggle preview / CTRL-R for ripgrep / CTRL-F for fzf' \
--bind '?:toggle-preview' \
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
--bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+rebind(ctrl-r)+transform-query(echo {q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f)" \
--bind "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)+transform-query(echo {q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r)" \
--bind "start:unbind(ctrl-r)" \
--prompt '1. ripgrep> ' \
--layout reverse \
--delimiter : \
--preview-window 'up,60%,border-bottom,~2,+{2}+2/2' \
--preview 'bat --style=full --color=always --highlight-line {2} {1}' | awk -F: '{print $1, $2}'
)"
if [[ -n "$file" ]]; then
vim "$file" "+$line"
fi
}
function fif() {
if [ ! "$#" -gt 0 ]; then
echo "Need a string to search for!"
return 1
fi
rg --files-with-matches --no-messages "$1" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 '$1' || rg --ignore-case --pretty --context 10 '$1' {}"
}
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
function findBigFiles() {
find ~/Documents/ -size +100M -ls | sort -k7nr
}