-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.zshrc
executable file
·416 lines (349 loc) · 9.67 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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# Created by Charles Gueunet <charles.gueunet+zsh@gmail.com>
# Follow the link (if any) to find the config folder
if [ -L "$HOME/.zshrc" ]; then
export ZDOTDIR=$(dirname `readlink -f $HOME/.zshrc`)
else
export ZDOTDIR="${HOME}/.config/zsh/"
fi
# tmux autostart
# ##############
# ZJ_SESSIONS=$(zellij list-sessions)
# NO_SESSIONS=$(echo "${ZJ_SESSIONS}" | wc -l)
# if [ "${NO_SESSIONS}" -ge 2 ]; then
# zellij attach \
# "$(echo "${ZJ_SESSIONS}" | sk)"
# else
# zellij attach -c
# fi
# if [[ -z "$ZELLIJ" ]]; then
# if [[ "$ZELLIJ_AUTO_ATTACH" == "true" ]]; then
# zellij attach -c
# else
# zellij
# fi
# if [[ "$ZELLIJ_AUTO_EXIT" == "true" ]]; then
# exit
# fi
# elif command -v tmux &> /dev/null && [[ $UID -ne 0 ]] && [[ -v DISPLAY ]] && [[ -v KITTY_WINDOW_ID ]] && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
# exec tmux
# fi
# notify
# ######
if [[ -v DISPLAY && -s "${ZDOTDIR:-$HOME}/notify/notify.plugin.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/notify/notify.plugin.zsh"
zstyle ':notify:*' error-title "Command failed (#{time_elapsed} seconds)"
zstyle ':notify:*' success-title "Command success (#{time_elapsed} seconds)"
zstyle ':notify:*' expire-time 2500
fi
# ZComet
# ######
# Clone zcomet if necessary
if [[ ! -f ${ZDOTDIR}/.zcomet/bin/zcomet.zsh ]]; then
command git clone "https://github.com/agkozak/zcomet.git" "${ZDOTDIR}/.zcomet/bin"
fi
source ${ZDOTDIR}/.zcomet/bin/zcomet.zsh
# Plugins list
source ${ZDOTDIR}/plugins_list.zsh
if [[ -a ${ZDOTDIR}/plugins_custom_list.zsh ]]; then
source ${ZDOTDIR}/plugins_custom_list.zsh
fi
# Run compinit and compile its cache
zcomet compinit
# # Plugins configuration
source ${ZDOTDIR}/plugins_conf.zsh
if [[ -a ${ZDOTDIR}/plugins_custom_conf.zsh ]]; then
source ${ZDOTDIR}/plugins_custom_conf.zsh
fi
# Kak mode
# #######
source "${ZDOTDIR}/kak-mode.zsh"
zle_highlight=(region:bg=green,fg=black)
# edit
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# prompt
# #####
eval "$(starship init zsh)"
# Global settings
# ###############
# cdr allows to come back to a previous visited directory
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
# OPTIONS
# If I could disable Ctrl-s completely I would!
setopt NO_FLOW_CONTROL
# beeps are annoying
setopt NO_BEEP
# avoid automatic change the title
DISABLE_AUTO_TITLE=true
ZSH_THEME_TERM_TITLE_IDLE="%~"
# Glob is clever research / completion
setopt NO_CASE_GLOB
setopt EXTENDED_GLOB
setopt NUMERIC_GLOB_SORT
# Remove annoying file redirection error
setopt CLOBBER
# Job control
setopt monitor
# automatic cd
setopt auto_cd
export DIRSTACKSIZE=8
setopt autopushd pushdminus pushdsilent pushdtohome
# autocomplete
zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f'
zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f'
zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
zstyle ':completion:*' format ' %F{yellow}-- %d --%f'
# fuzzy completion when mistype
bindkey "^Xa" _expand_alias
zstyle ':completion:*' completer _expand_alias _complete _match _approximate
zstyle ':completion:*' regular true
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric
zstyle ":completion:*" list-colors "${(s.:.)LS_COLORS}" # color output with LS_COLORS
zstyle ":fzf-tab:complete:cd:*" fzf-preview 'eza -1 --color=always $realpath' # Preview directories with eza
# history
HISTFILE=${ZDOTDIR}/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt INC_APPEND_HISTORY
setopt HIST_IGNORE_SPACE
setopt HIST_IGNORE_DUPS
setopt BANG_HIST
setopt HIST_REDUCE_BLANKS
# key binding
# Tab -> complete or next completion
bindkey '^i' expand-or-complete-prefix
# Multiple dot to up
if is-at-least 5.0.0 && [[ ! $UID -eq 0 ]]; then
## http://www.zsh.org/mla/users/2010/msg00769.html
function rationalise-dot() {
local MATCH # keep the regex match from leaking to the environment
if [[ $LBUFFER =~ '(^|/| | |'$'\n''|\||;|&)\.\.$' && ! $LBUFFER = p4* ]]; then
#if [[ ! $LBUFFER = p4* && $LBUFFER = *.. ]]; then
LBUFFER+=/..
else
zle self-insert
fi
}
zle -N rationalise-dot
bindkey . rationalise-dot
bindkey -M isearch . self-insert
fi
# Aliases
# #######
typeset -a ealiases
ealiases=()
function ealias()
{
alias $1
ealiases+=(${1%%\=*})
}
function expand-ealias()
{
if [[ $LBUFFER =~ "\<(${(j:|:)ealiases})\$" ]]; then
zle _expand_alias
zle expand-word
fi
zle magic-space
}
zle -N expand-ealias
# Custom PATH
if [[ -d "${ZDOTDIR}/bin" ]]; then
export PATH=$PATH:"${ZDOTDIR}/bin"
fi
if [[ -d "${HOME}/.cargo/bin" ]]; then
export PATH=$PATH:${HOME}/.cargo/bin
fi
# builtin
alias sz="source $HOME/.zshrc"
alias clear="printf '\33[H\33[2J'"
alias startm="XINITRC=$HOME/.xinitrc_mate startx"
if type eza >/dev/null 2>&1; then
alias ls='eza --group-directories-first'
alias l='eza -lh --group-directories-first'
alias ll='eza -l --group-directories-first --all'
alias lt='eza -T --git-ignore --level=2 --group-directories-first'
alias lg='eza -l --all --group-directories-first --git'
else
alias l='ls -lah'
alias ll='ls -alF'
alias la='ls -A'
fi
# cmake
ealias b="mkdir build"
ealias cb="cd build"
ealias rb="rm -rf build/"
ealias rmcmake="rm -rf CMakeFiles Makefile cmake_install.cmake CMakeCache.txt build.ninja rules.ninja"
alias -g CC="-C ~/.config/cmake/base.cmake"
# alias -g NM="-G 'Ninja Multi-Config'"
alias -g NN="-G 'Ninja'"
alias -g CD="--config Debug"
alias -g CR="--config Release"
alias -g BB="--build build"
alias -g BP="--build ."
alias -g TI="--target install"
alias -g MP="-- -j 6 -l 5"
# editor
alias ks='. ${ZDOTDIR}/bin/kks-new'
alias kd='. ${ZDOTDIR}/bin/kks-detach'
alias kk='. ${ZDOTDIR}/bin/kks-kill'
alias kss='eval $(kks-switch)'
alias :q="exit"
alias :e="ke"
alias a="kks a"
alias cat="bat --paging=never"
alias less="bat --paging=always"
# git
ealias gitgraph="git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
alias GD="GIT_EXTERNAL_DIFF=difft"
# tmux
ealias t="tmux -2"
ealias ta="tmux -2 a"
function tmux-kill-unnamed {
tmux ls -F'#{session_name}'|grep -E '^[0-9]+$'|xargs -I% tmux kill-session -t "=%"
}
# zellij
ealias z="zellij"
ealias za="zellij attach "
# Keyboard qwerty with accent
if [[ -f "${HOME}/.Xmodmap" ]]; then
alias rebind="setxkbmap -option compose:rctrl ; xmodmap ${HOME}/.Xmodmap"
else
alias rebind='setxkbmap -option compose:ralt'
fi
# Alias post command
alias -g G="| grep "
alias -g L="| less "
alias -g T="| tee -a "
alias -g S="| sed "
alias -g V="| vim - "
alias -g XC="| xsel --clipboard "
alias -g XV="\`xsel --clipboard --output\`"
alias -g X="| xargs "
alias -s {bib, c, cmake, cpp, h, hpp, md, rb, tex, txt, xml}="$EDITOR"
alias -s {vtu, vti, vtp, vtr, stl}="paraview"
# Env
export VISUAL="ke"
export EDITOR=$VISUAL
export SVN_EDITOR=$EDITOR
export GIT_EDITOR=$EDITOR
export TIG_EDITOR=$EDITOR
export KEYTIMEOUT=1
export BC_LINE_LENGTH=0 # fix for bc when no newline
export GOPATH=$HOME/Software/go
# Functions (binded to keys)
# #########
# ctrl z back and forth
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^z' fancy-ctrl-z
# ctrl v file manager
vicd()
{
# from https://wiki.vifm.info/index.php?title=How_to_set_shell_working_directory_after_leaving_Vifm
# Syncro vifm and shell
local dst="$(command vifm --choose-dir - .)"
if [ -z "$dst" ]; then
echo 'Directory picking cancelled/failed'
return 1
fi
cd "$dst"
}
vifm-call() {
if [[ -z $BUFFER ]]; then
# interpreted at start, not when leaving
BUFFER="vicd"
zle accept-line
fi
}
zle -N vifm-call
bindkey '^v' vifm-call
# ctrl b pueue status
pueue-call() {
if [[ -z $BUFFER ]]; then
# interpreted at start, not when leaving
BUFFER="clear; pueue status"
zle accept-line
fi
}
zle -N pueue-call
bindkey '^b' pueue-call
# ctrl g command replace
substitute-last() {
if [[ -z $BUFFER ]]; then
# interpreted at start, not when leaving
BUFFER="!!:gs/"
CURSOR=6
fi
}
zle -N substitute-last
bindkey '^g' substitute-last
function mkcd {
mkdir -p -- "$1"
cd -P -- "$1"
}
# mv in folder and cd when it is done
function mvc(){
lastArg=${@:$#}
if [ -d "$lastArg" ]; then
mv $@
cd $lastArg
unset lastArg
else
echo "Last argument is not a folder"
return 1
fi
}
# clear on enter
if ! typeset -f magic-enter > /dev/null; then
magic-enter() {
if [[ -z "$BUFFER" ]]; then
zle clear-screen
else
# Call built-in accept-line
zle .accept-line
fi
}
zle -N accept-line magic-enter
fi
# Ctrl o: previous vim/kak like
magic-popd () {
if [[ -z $BUFFER ]]; then
popd
zle accept-line
fi
}
zle -N magic-popd
bindkey "^o" magic-popd
# Additional conf
# ###############
# fuzzy completion with ctrl-r / ctrl-t / alt-c
if [[ -f "${ZDOTDIR}/fzf_binding.zsh" ]]; then
source "${ZDOTDIR}/fzf_binding.zsh"
fi
if [[ -f "${ZDOTDIR}/LS_COLORS" ]]; then
eval $(dircolors -b "${ZDOTDIR}/LS_COLORS")
fi
# direnv
if command -v direnv &> /dev/null; then
eval "$(direnv hook zsh)"
fi
# broot launcher
if [[ -f "${HOME}/.config/broot/launcher/bash/br" ]]; then
source "${HOME}/.config/broot/launcher/bash/br"
fi
# Custom conf (in $ZDOTDIR or $HOME)
if [[ -f "${ZDOTDIR}/zshrc_custom.zsh" ]]; then
source "${ZDOTDIR}/zshrc_custom.zsh"
fi