-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshrc
357 lines (308 loc) · 10.7 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
# Launch tmux if there's no tmux session already running
if [[ ! $(tmux list-sessions 2> /dev/null) ]]; then exec tmux; fi
# Enable Powerlevel10k instant prompt. Should stay close to the top
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
# Load Fzf stuff. `key-bindings.zsh` has to be loaded before Atuin is to
# prevent Fzf from overriding the `Ctrl-R` key binding
[ -f /usr/share/fzf/key-bindings.zsh ] && source /usr/share/fzf/key-bindings.zsh
[ -f /usr/share/fzf/completion.zsh ] && source /usr/share/fzf/completion.zsh
ZSH_THEME="agnoster" # Backup theme
DISABLE_AUTO_UPDATE="true"
export ANTIGEN_CACHE=false # Fixes issue with completion for azure-cli not working
# ------------- Antigen -------------
source /usr/share/zsh/share/antigen.zsh
autoload -Uz compinit && compinit
antigen use oh-my-zsh # Load the oh-my-zsh's library.
antigen bundles << EOBUNDLES
pip
npm
lein
command-not-found
colorize
colored-man-pages
extract
zsh-users/zsh-autosuggestions
zsh-users/zsh-syntax-highlighting
zsh-users/zsh-history-substring-search
zsh-users/zsh-completions
l4u/zsh-output-highlighting
mawkler/zsh-bd
hlissner/zsh-autopair
unixorn/autoupdate-antigen.zshplugin
Aloxaf/fzf-tab
olets/zsh-abbr@main
lukechilds/zsh-better-npm-completion
EOBUNDLES
antigen theme romkatv/powerlevel10k
antigen apply # Tell Antigen that you're done.
# -----------------------------------
HYPHEN_INSENSITIVE="true" # Use hyphen-insensitive completion
ENABLE_CORRECTION="true" # Enables command auto-correction
COMPLETION_WAITING_DOTS="true" # Displays red dots whilst waiting for completion
DISABLE_UNTRACKED_FILES_DIRTY="true" # Speeds up VCS status check in large repositories
KEYTIMEOUT=1 # Speeds up mode switching
unsetopt autocd # Don't CD when typing the name of dirs
if type nvim &> /dev/null; then
export VISUAL=nvim
else
export VISUAL=vim
fi
export EDITOR=$VISUAL
export NVIM_MINIMAL=1 # Load Neovim with less plugins when called from zsh
# Work config
if [[ -r $HOME/.zsh/work.zsh ]]; then
source $HOME/.zsh/work.zsh
fi
# Change cursor shape for different vi modes
function zle-keymap-select {
if [[ $KEYMAP == vicmd ]] || [[ $1 = 'block' ]]; then
echo -ne '\e[1 q'
elif [[ $KEYMAP == main ]] || [[ $KEYMAP == viins ]] || [[ $KEYMAP = '' ]] || [[ $1 = 'beam' ]]; then
echo -ne '\e[5 q'
fi
}
zle -N zle-keymap-select
zle-line-init() { zle-keymap-select 'beam'} # Start with beam shape cursor on zsh startup and after every command.
bindkey -v # Enable Vi mode
# Keybindings
# For list of keybindings run `man zshzle`, `zle -al` or `bindkey`
bindkey -s '^[l' '^Qls^J' # Alt-L clears text before running `ls`
bindkey -s '^[L' '^Qls -a^J' # Alt-Shift-L also shows hidden files
bindkey -s '^[[2~' '^X^E' # `Insert` key opens $EDITOR
bindkey '^P' up-line-or-beginning-search
bindkey '^N' down-line-or-beginning-search
bindkey '^[p' history-substring-search-up
bindkey '^[n' history-substring-search-down
bindkey '\e\C-?' backward-kill-word # Alt-backspace
bindkey '^[[Z' reverse-menu-complete # Shift-tab completes backwards
bindkey -M menuselect '^P' up-history
bindkey -M menuselect '^N' down-history
# Vi-mode config
bindkey '^F' forward-char
bindkey '^[f' forward-word
bindkey '^B' backward-char
bindkey '^[b' backward-word
bindkey '^_' undo
bindkey '^U' kill-whole-line
bindkey '^K' kill-line
bindkey '^Q' push-line # Clears the command line and restores after new command
bindkey -M vicmd -s '^[l' 'A^Qls^J'
bindkey -M vicmd -s '^[L' 'A^Qls -a^J'
bindkey -M vicmd -s '_' '^'
bindkey -M vicmd '^P' up-line-or-beginning-search
bindkey -M vicmd '^N' down-line-or-beginning-search
bindkey -M vicmd '^[p' history-substring-search-up
bindkey -M vicmd '^[n' history-substring-search-down
bindkey -M vicmd '\e\C-?' backward-kill-word
bindkey -M vicmd 'v' visual-mode # Use v for visual mode and V to
bindkey -M vicmd 'V' edit-command-line # open current line in $VISUAL
# Fixes issue with `bindkey -v` making `abbr` not work
bindkey -M viins " " abbr-expand-and-insert
bindkey -M viins "^M" abbr-expand-and-accept
paste_from_clipboard() {
local paste="$(xclip -o -selection clipboard)"
zle -U "$paste"
}
zle -N paste_from_clipboard
bindkey '\eP' paste_from_clipboard # Alt-shift-P
# Fzf
FZF_COLORS="
--color=fg:-1
--color=fg+:#61afef
--color=bg:-1
--color=bg+:#444957
--color=hl:#E06C75
--color=hl+:#E06C75
--color=gutter:-1
--color=pointer:#61afef
--color=marker:#98C379
--color=header:#61afef
--color=info:#98C379
--color=spinner:#61afef
--color=prompt:#c678dd
--color=border:#798294
"
export FZF_DEFAULT_OPTS="
--history=$HOME/.fzf_history
--history-size=10000
--height 50%
--pointer='▶'
$FZF_COLORS
"
EZA_DIR_PREVIEW="eza \
--color=always -T \
--level=2 \
--icons auto \
--git-ignore \
--git \
--ignore-glob=.git \
"
# bat config is in `~/.config/bat/config`
export FZF_CTRL_T_OPTS="--preview 'bat --style=numbers --color=always --line-range :100 {}'"
export FZF_CTRL_T_COMMAND="rg --hidden --files --no-messages"
export FZF_ALT_C_COMMAND="fd --type directory -H --ignore-file ~/.ignore"
export FZF_ALT_C_OPTS="--preview=\"$EZA_DIR_PREVIEW {}\""
export FZF_CTRL_R_COMMAND=""
# Alt-T: Like Fzf's Ctrl-T, but lets you select directories instead of files
fzf_select_directories() {
local selected_dirs=$(fd --type directory --exclude .git \
2> /dev/null \
| fzf --multi --reverse --preview="$EZA_DIR_PREVIEW {}"
)
LBUFFER+=$(echo $selected_dirs | xargs)
zle redisplay
}
zle -N fzf_select_directories
bindkey '\et' fzf_select_directories
bindkey -M vicmd '\et' fzf_select_directories
# Create a new directory and enter it
mkcd() {
mkdir -p $@ && cd $@
}
# Count the total number of files in directory
countfiles() {
tree $@ | tail -n 1
}
# Count the number of files in each immediate subdirectory
countallfiles() {
fd -t d --hidden --max-depth=1 | xargs -d $'\n' sh -c 'for arg do echo $arg `tree $arg | tail -n 1`; done' _ | column -t | sort -Vr -k 4n | tac
}
tree-pager() {
eza --icons auto --color always --tree $@ | less -Fn
}
# Abbreviations are in ~/.config/zsh/abbreviations
alias zshrc='nvim ~/.zshrc'
alias vimrc='nvim ~/.vimrc'
alias src='exec zsh'
alias listfiles='find . -type f -iname "*"'
alias xs='xargs -I % sh -c'
alias less='less -mgiJr --underline-special --SILENT'
alias xclip='xclip -selection c'
alias ls='eza --icons auto'
alias m='make'
alias tree='eza --icons never --tree --git-ignore'
alias Tree='tree-pager'
alias installed='yay -Qqe | bat'
alias remove-non-dependencies='sudo pacman -Rns $(pacman -Qtdq)'
alias open='xdg-open &>/dev/null'
alias errorlogs='journalctl --since=today'
alias screenkey='screenkey -t 1.5 -s small'
alias wifi='nmcli'
alias n='nmcli device wifi connect'
alias Bat='bat --pager="less -mgi --underline-special --SILENT"'
alias myip='hostname -i'
alias yaz='yay -Slq | fzf -m --preview "yay -Si {1}"| xargs -ro yay -S --noconfirm'
alias yaz-remove='yay -Qeq | fzf -m --preview "yay -Qi {1}" | xargs -ro yay -Rs'
alias mv='mv -i'
alias pdf_clip='curl -Ls `xclip -o` | (zathura - &)'
alias ag="ag --hidden --pager='less -R'"
alias rg="rg --hidden --smart-case"
alias fd="fd --hidden"
alias dump-dconf='dconf dump /org/gnome/shell/extensions/ > .dotfiles/gnome-extensions.dconf'
alias fix-screen='xset -dpms'
alias mvc='mullvad connect'
alias mvd='mullvad disconnect'
alias mvr='mullvad reconnect'
# Delta
export DELTA_PAGER='less -mgi --underline-special --SILENT'
# Git:
_master_branch() {
if git rev-parse --quiet --verify master > /dev/null; then
echo 'master'
else
echo 'main';
fi
}
# Pulls to master and then rebases into current branch
function grm() {
if [[ 'git rev-parse --is-inside-work-tree 2>/dev/null' ]]; then
echo "Rebasing onto `_master_branch`..."
git pull --autostash origin `_master_branch`:`_master_branch`
git rebase --autostash `_master_branch`
else
echo 'Not inside a git repository'
fi
}
alias pull-all='ls -d */ | xargs -P10 -I {} sh -c "echo Pulling changes in {}... && git -C {} pull"'
alias g='git'
alias gs='git status'
alias gl='git log --decorate'
alias gd='git diff -- :!package-lock.json :!yarn.lock :!Cargo.lock'
alias gds='git diff --staged -- :!package-lock.json :!yarn.lock :!Cargo.lock'
alias gco='git checkout'
alias gcom='git checkout `_master_branch`'
alias gmm='git merge master'
alias gp='git pull --autostash'
alias gP='git push'
alias gb='git branch'
alias gw='git whatchanged'
alias ga='git add'
alias gcm='git commit -mv'
alias gcam='git commit -avm'
alias gca='git commit -av'
alias gcaa='git commit -av --amend'
alias gcA='git commit -v --amend'
alias gu='git diff HEAD@{1} HEAD'
alias gly='git log --since="yesterday"'
alias gr='git reset'
alias grc='git rebase --continue'
alias gra='git rebase --abort'
alias gdm='git diff `_master_branch`..HEAD'
alias gdu='diff upstream/`_master_branch`'
alias gru='git pull --rebase --autostash upstream `_master_branch`'
alias gsp='git stash pop'
alias gss='git stash show -p'
alias glm='git log `_master_branch`'
alias gldm='git log --decorate --oneline `_master_branch`..'
alias gds='git diff --staged'
# Dotfiles
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
alias dot='dotfiles'
alias dots='dot status'
# Completion for azure-cli
if [[ -r '/opt/azure-cli/bin/az.completion.sh' ]]; then
source /opt/azure-cli/bin/az.completion.sh
fi
# Zoxide
eval "$(zoxide init zsh)"
# Alt-z - Zoxide with Fzf
fzf-zoxide() {
eval "zi"
zle accept-line
}
zle -N fzf-zoxide
bindkey '^[z' fzf-zoxide
# Zoxide's Fzf options
export _ZO_FZF_OPTS="
--no-sort
--keep-right
--info=inline
--layout=reverse
--exit-0
--select-1
--bind=ctrl-z:ignore
--preview-window=right
--preview=\"$EZA_DIR_PREVIEW {2..} \"
$FZF_DEFAULT_OPTS
"
alias cd=z
alias zoxide-add-directories="fd --type directory --max-depth 1 | xargs zoxide add"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh
# fzf-tab
# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# set descriptions format to enable group support
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# preview directory's content with eza when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
# switch group using `ctr-B` and `ctrl-F`
zstyle ':fzf-tab:*' switch-group 'ctrl-B' 'ctrl-F'
# nvm
source /usr/share/nvm/init-nvm.sh
# Atuin
eval "$(atuin init zsh --disable-up-arrow)"