-
Notifications
You must be signed in to change notification settings - Fork 1
/
zshrc
335 lines (261 loc) · 10.2 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
# _
# | |
# ____ ___ | |__ _ __ ___
# |_ // __|| '_ \ | '__|/ __|
# / / \__ \| | | || | | (__
# /___||___/|_| |_||_| \___|
#
# Profiling
# zmodload zsh/zprof
# =================================================================
# Autoload
# =================================================================
autoload -U history-search-end
autoload -U zmv
autoload -Uz compinit
# =================================================================
# Shortcuts
# =================================================================
bindkey -e
# Enter vim mode
bindkey '^[v' vi-cmd-mode
# fix keys
bindkey "^[[3~" delete-char
bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line
# Do not catch Ctrl+q and Ctrl+s by the terminal
# (I use it in vim)
stty start undef
stty stop undef
# Alt+i to search inside files
zle -N file-search
bindkey '^[i' file-search
# Alt+e to open recent files
zle -N file-recent
bindkey '^[e' file-recent
# Alt+p to open file in subdirectories
zle -N file-edit
bindkey '^[p' file-edit
# Alt+d to go to recent (almost any reasonable) directory
zle -N dir-recent
bindkey '^[d' dir-recent
# Alt+j to go to any subdirectory
zle -N dir-open
bindkey '^[j' dir-open
# Alt+l to copy last command into clipboard
zle -N last-command
bindkey '^[l' last-command
# Alt+n to edit command line
autoload -z edit-command-line
zle -N edit-command-line
bindkey '^[n' edit-command-line
# Alt+o to insert last command output
zle -N insert-last-output
bindkey '^[o' insert-last-output
# Alt+Backspace to remove last path segment (like in bash)
bindkey "^[^?" vi-backward-kill-word
# Alt+a accept-and-hold = execute line and keep editing the line
# Alt+b backward-word
# Alt+c fzf-cd-widget = jump to directory via fzf
# Alt+f forward-word
# Alt+g get-line = insert line from buffer
# Alt+h run-help = man page for command under cursor
# Alt+m = urxvt: list all urls in terminal
# Alt+q push-line
# Alt+r = urxvt: activate search
# Alt+s = urxvt: scrollback search
# Alt+t transpose-words
# Alt+u = urxvt: open last url in terminal
# Alt+v = urxvt: activate vim movement
# Alt+w copy-region-as-kill
# Alt+x execute-named-cmd
# Alt+y yank-pop
# Alt+z execute-last-named-cm
# =================================================================
# Options
# =================================================================
# append history list to the history file (important for multiple parallel zsh sessions!)
setopt inc_append_history
# import new commands from the history file also in other zsh-session
setopt share_history
# save each command's beginning timestamp and the duration to the history file
setopt extended_history
# if a new command line being added to the history list duplicates an older one, the older command is removed from the list
setopt hist_ignore_all_dups
# remove command lines from the history list when the first character on the line is a space
setopt hist_ignore_space
# allow more patterns to be expanded on command line
setopt extended_glob
# disable beeping (e.g. after tab completion)
unsetopt beep
HISTFILE=$HOME/.zsh_history
HISTSIZE=100000
HISTFILESIZE=100000
SAVEHIST=100000
KEYTIMEOUT=1
# =================================================================
# Completion
# =================================================================
# 0 -- vanilla completion (abc => abc)
# 1 -- smart case completion (abc => Abc)
# 2 -- word flex completion (abc => A-big-Car)
# 3 -- full flex completion (abc => ABraCadabra)
zstyle ':completion:*' matcher-list '' \
'm:{a-z\-}={A-Z\_}' \
'r:[^[:alpha:]]||[[:alpha:]]=** r:|=* m:{a-z\-}={A-Z\_}' \
'r:[[:ascii:]]||[[:ascii:]]=** r:|=* m:{a-z\-}={A-Z\_}'
which npm >/dev/null && source <(npm completion)
# tabtab source for packages
# uninstall by removing these lines
[[ -f ~/.config/tabtab/zsh/__tabtab.zsh ]] && . ~/.config/tabtab/zsh/__tabtab.zsh || true
[ -x /home/linuxbrew/.linuxbrew/bin/brew ] && fpath+=("$(brew --prefix)/share/zsh/site-functions")
fpath+=(~/.zsh/completion)
# turborepo
fpath+=(~/.zsh/completion/turbo.sh)
autoload bashcompinit && bashcompinit
# =================================================================
# Colors
# =================================================================
# eval $(dircolors ~/dotfiles/colors/dircolors)
LIST_FILES_COMMAND='fd --hidden --no-ignore --exclude .git --exclude node_modules --exclude build/ --exclude dist/ --exclude .lock'
# Numbers represent terminal colors, see kitty.conf
# bg+ is background color for active item (same color as selection in my vim)
export FZF_DEFAULT_OPTS="
--color bg:#2d2d2d,hl:#d8a657,bg+:#45403d,hl+:#d8a657
--color pointer:1,info:8,spinner:8,header:8,prompt:12,marker:#d8a657
--exit-0
--select-1
--reverse
--height=30
"
export FZF_CTRL_T_COMMAND=$LIST_FILES_COMMAND
export forgit_log=fglo
export forgit_diff=fgd
export forgit_add=fga
export forgit_reset_head=fgres # git restore --staged
export forgit_ignore=fgi
export forgit_checkout_file=fgre # git restore
export forgit_checkout_branch=fgcb
export forgit_branch_delete=fgbd
export forgit_checkout_tag=fgct
export forgit_checkout_commit=fgco
export forgit_revert_commit=fgrc
export forgit_clean=fgclean
export forgit_stash_show=fgss
export forgit_cherry_pick=fgcp
export forgit_rebase=fgrb
export forgit_blame=fgbl
export forgit_fixup=fgfu
export FORGIT_FZF_DEFAULT_OPTS="
--color bg:#2d2d2d,hl:#d8a657,bg+:#45403d,hl+:#d8a657
--color pointer:1,info:8,spinner:8,header:8,prompt:12,marker:#d8a657
--reverse
--height=100%
"
export MC_SKIN=/home/lukas/.config/mc/solarized-light.ini
export BAT_THEME="TwoDark"
export BAT_PAGER="less -RF"
# =================================================================
# Plugins
# =================================================================
# Antidote
antidote_dir=$(brew --prefix)/opt/antidote/share/antidote
plugins_txt=${HOME}/.zsh_plugins.txt
plugins_txt_dotfiles=${HOME}/dotfiles/zsh_plugins.txt
static_file=${HOME}/.zsh_plugins.zsh
# Clone antidote if necessary and generate a static plugin file
if [[ ! $static_file -nt $plugins_txt ]]; then # static_file is newer then plugins_txt
[[ -e $antidote_dir ]] ||
# antidote_dir does not exists
git clone --depth=1 https://github.com/mattmc3/antidote.git $antidote_dir
(
source $antidote_dir/antidote.zsh
[[ -e $plugins_txt ]] || ln -s $plugins_txt_dotfiles $plugins_txt # create plugins_txt if it not exists
antidote bundle <$plugins_txt >$static_file
)
fi
source $static_file # source the static plugins file
unset antidote_dir plugins_txt static_file # cleanup
# end Antidote
# Fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Zoxide
which zoxide >/dev/null && eval "$(zoxide init zsh)"
# Atuin
eval "$(atuin init zsh --disable-up-arrow)"
# =================================================================
# Terminal
# =================================================================
# My terminal (kitty now) for some reason does not display tab title according to pure prompt logic
if [[ $TERM =~ "kitty" ]]; then
precmd () {
kitty @ set-tab-title "$(basename $(dirname ${PWD}))/$(basename ${PWD})"
}
fi
if [[ $TERM =~ "kitty" ]]; then
preexec() {
kitty @ set-tab-title "$(basename $(dirname ${PWD}))/$(basename ${PWD}): $1"
}
fi
if [[ -n $KITTY_INSTALLATION_DIR ]]; then
export KITTY_SHELL_INTEGRATION="enabled"
autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration
kitty-integration
unfunction kitty-integration
fi
# =================================================================
# Directories
# =================================================================
# Save current working directory into file.
# Called by zsh every time current working directory is changed.
chpwd() {
echo "$PWD" > ~/.cwd
}
# =================================================================
# Aliases and functions
# =================================================================
source ~/dotfiles/functions
source ~/dotfiles/aliases
# =================================================================
# WSL config
# =================================================================
if [[ $WSL == "true" ]]; then
source ~/dotfiles/zshenv.wsl
source ~/dotfiles/zshrc.wsl
source ~/dotfiles/aliases.wsl
fi
# =================================================================
# Local config
# =================================================================
[[ -f ~/.functions.local ]] && source ~/.functions.local
[[ -f ~/.zshenv.local ]] && source ~/.zshenv.local
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local
[[ -f ~/.aliases.local ]] && source ~/.aliases.local
# =================================================================
# History database
# =================================================================
# source ~/opt/bash_database_history/zsh_trap.sh
# =================================================================
# Last command
# =================================================================
# Source: https://gist.github.com/ctechols/ca1035271ad134841284
# On slow systems, checking the cached .zcompdump file to see if it must be
# regenerated adds a noticable delay to zsh startup. This little hack restricts
# it to once a day. It should be pasted into your own completion file.
#
# The globbing is a little complicated here:
# - '#q' is an explicit glob qualifier that makes globbing work within zsh's [[ ]] construct.
# - 'N' makes the glob pattern evaluate to nothing when it doesn't match (rather than throw a globbing error)
# - '.' matches "regular files"
# - 'mh+24' matches files (or directories or whatever) that are older than 24 hours.
if [[ -n ${HOME}/.zcompdump(#qN.mh+24) ]]; then
compinit;
else
compinit -C;
fi;
# The next line updates PATH for Netlify's Git Credential Helper.
[ -f '/home/lukas/.netlify/helper/path.zsh.inc' ] && source '/home/lukas/.netlify/helper/path.zsh.inc'
# find-alias
[[ -s "$HOME/.find-alias.sh" ]] && source "$HOME/.find-alias.sh"
# Profiling
# zprof