-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zshrc
549 lines (437 loc) · 15.8 KB
/
dot_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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# Environment
## Import environment variables
[[ -f ~/.zshenv ]] && source ~/.zshenv
## Import machine-specific .zshrc
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local
## Default apps
export BROWSER='chromium'
export EDITOR='nvim'
export TERM='terminology'
export LANG="en_US.UTF-8" # Default locale
[[ -z "$SSH_CONNECTION" ]] && xset b off # Disable beeps
export PATH="$HOME/bin:$PATH" # Add binaries from ~/bin to $PATH
# Startup
cowthink $(fortune -c) # Cow greeting you on launch
export PS1="%~ $ " # Status in terminal
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
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
# Look
if [[ -z "$SSH_CONNECTION" ]] ; then
## TODO: dynamic-colors (NEEDED?)
#export PATH="$HOME/.urxvt/dynamic-colors/bin:$PATH"
# dynamic-colors init
## TODO: Yaourt
# export YAOURT_COLORS="nb=1:pkg=1:ver=1;32:lver=1;45:installed=1;42:grp=1;34:od=1;41;5:votes=1;44:dsc=0:other=1;35""
# >Powerlevel10k: To customize prompt, run
# `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
fi
# Input
## General
### Emacs keybindings by default
### Don't recommend to use vim keybindings except for big inline scripts
bindkey -e
### transition between modes takes 0.1s instead of 0.4s
export KEYTIMEOUT=1
## Keymaps
### Use vim cli mode
bindkey '^P' up-history
bindkey '^N' down-history
# ctrl-r starts searching history backward
bindkey '^r' history-incremental-search-backward
# Delete key fix
bindkey "^[[3~" delete-char
# Bang! Previous Command Hotkeys
# print previous command but only the first nth arguments
# Alt+1, Alt+2 ...etc
# http://www.softpanorama.org/Scripting/Shellorama/bash_command_history_reuse.shtml#Bang_commands
bindkey -s '\e1' "!:0 \t" # last command
bindkey -s '\e2' "!:0-1 \t" # last command + 1st argument
bindkey -s '\e3' "!:0-2 \t" # last command + 1st-2nd argument
bindkey -s '\e4' "!:0-3 \t" # last command + 1st-3rd argument
bindkey -s '\e5' "!:0-4 \t" # last command + 1st-4th argument
bindkey -s '\e`' "!:0- \t" # all but the last argument
bindkey -s '\e9' "!:0 !:2* \t" # all but the 1st argument (aka 2nd word)
### backspace and ^h working even after returning from command mode
bindkey '^?' backward-delete-char
bindkey '^h' backward-delete-char
# Typing and completion
## zsh completion
autoload -Uz compinit
compinit
## Use bash-completion, if available
autoload bashcompinit
bashcompinit
## auto-correction
setopt correctall
## Disable the need of `rehash` on new executable in $PATH
setopt nohashdirs
## Auto-rehash on completion (in case new binaries were added to $PATH)
zstyle ":completion:*:commands" rehash 1
## Add bash_completions for a more wholesome experience
if [ -f /etc/bash_completion ]; then source /etc/bash_completion; fi
## Don't complete uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \
avahi ftp mysql systemd-bus-proxy usbmux bacula git nobody \
systemd-journal-gateway uuidd bin ntp systemd-journal-remote \
colord http polkitd systemd-journal-upload daemon kdm postfix \
systemd-network dbus postgres systemd-resolve deluge \
systemd-timesync mail rtkit test
## .... unless we really want to.
zstyle '*' single-ignored show
## ssh - config host entries completion
zstyle -s ':completion:*:hosts' hosts _ssh_config
[[ -r ~/.ssh/config ]] && _ssh_config+=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p'))
zstyle ':completion:*:hosts' hosts $_ssh_config
# History
# Append to history file
setopt appendhistory
# Limits
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=10000
# Plugins
export NVM_DIR="$HOME/.nvm"
export NVM_LAZY_LOAD=true
export NVM_AUTO_USE=true
## >Zim
zstyle ':zim:zmodule' use 'degit'
ZIM_HOME=~/.zim
### Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
mkdir -p ${ZIM_HOME} && wget -nv -O ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
### Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
source ${ZIM_HOME}/zimfw.zsh init -q
fi
### Initialize modules.
source ${ZIM_HOME}/init.zsh
## >fzf completion
if [ -f /usr/share/fzf/key-bindings.zsh ]; then source "/usr/share/fzf/key-bindings.zsh"; fi
if [ -f /usr/share/fzf/completion.zsh ]; then source "/usr/share/fzf/completion.zsh"; fi
# Packages / Libraries / Tools
## >nvim
alias n="nvim"
## >tmuxinator
alias tx="tmuxinator"
alias txn="tmuxinator new"
alias txs="tmuxinator start"
alias txsp="tmuxinator stop"
alias txe="tmuxinator edit"
alias txd="tmuxinator delete"
alias txcp="tmuxinator copy"
## >Chezmoi
alias ch="chezmoi"
alias cha="chezmoi add"
alias chap="chezmoi apply"
alias chr="chezmoi remove"
alias chu="chezmoi update"
alias chcd="chezmoi cd"
alias chm="chezmoi merge"
alias chma="chezmoi merge-all"
alias chra="chezmoi re-add"
alias chs="chezmoi status"
## >NPM / Yarn
### User-level global node modules
export PATH="$HOME/.node_modules/bin:$PATH"
export PATH="$HOME/.yarn/bin:$PATH"
## >Python
# More binaries
export PATH=$HOME/.local/bin:$PATH
# Auto-activate venv's
python_venv() {
MYVENV=./venv
# when you cd into a folder that contains $MYVENV
[[ -d $MYVENV ]] && source $MYVENV/bin/activate > /dev/null 2>&1
# when you cd into a folder that doesn't
[[ ! -d $MYVENV ]] && deactivate > /dev/null 2>&1
}
autoload -U add-zsh-hook
add-zsh-hook chpwd python_venv
### pips(): pip install & save
function pips() {
for pkg in $@; do
pip install "$pkg" && {
name="$(pip show "$pkg" | grep Name: | awk '{print $2}')";
version="$(pip show "$pkg" | grep Version: | awk '{print $2}')";
echo "${name}==${version}" >> requirements.txt;
}
done
}
# Autocompletions for `pipx`
eval "$(register-python-argcomplete pipx)"
# `IPython` default config directory
export IPYTHONDIR=$HOME/.ipython/profile_default/
### Add personal projects to import path
export PYTHONPATH="$PYTHONPATH:venv/lib/python3.11/site-packages/:$HOME/Projects"
## >> Sourcery plugin
alias pysr="sourcery review ."
## >Ruby
#export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
#export PATH="$PATH:$GEM_HOME/bin"
## >RVM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
export PATH="$PATH:$HOME/.rvm/bin"
## >nnn
export NNN_PLUG='f:finder;o:fzopen;p:mocq;d:diffs;t:nmount;v:imgview'
# move pwd to recently closed directory by nnn
nn()
{
# Block nesting of nnn in subshells
[ "${NNNLVL:-0}" -eq 0 ] || {
echo "nnn is already running"
return
}
# The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set)
# If NNN_TMPFILE is set to a custom path, it must be exported for nnn to
# see. To cd on quit only on ^G, remove the "export" and make sure not to
# use a custom path, i.e. set NNN_TMPFILE *exactly* as follows:
# NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
# Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
# stty start undef
# stty stop undef
# stty lwrap undef
# stty lnext undef
# The command builtin allows one to alias nnn to nn, if desired, without
# making an infinitely recursive alias
command nnn "$@"
[ ! -f "$NNN_TMPFILE" ] || {
. "$NNN_TMPFILE"
rm -f "$NNN_TMPFILE" > /dev/null
}
}
## >PHP / Composer / wp-cli
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
## >ZMV
## http://onethingwell.org/post/24608988305/zmv
autoload zmv
## >Flatpak
export XDG_DATA_DIRS="/var/lib/flatpak/exports/share:$HOME/.local/share/flatpak/exports/share:$XDG_DATA_DIRS"
# >Torsocks
#export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/torsocks/libtorsocks.so"
#source /usr/bin/torsocks on
## >Android Studio
export ANDROID_SDK_ROOT="$HOME/.android/sdk"
export ANDROID_HOME="$HOME/.android/sdk"
export PATH="$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/platform-tools/bin:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$PATH"
# >Java
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
export PATH=$JAVA_HOME/bin:/usr/share/java:/usr/lib/eclipse/plugins:$PATH
# >Eclipse
export PATH=/opt/eclipse:$PATH
# Aliases
## Navigation
alias x='cd "$(xplr --print-pwd-as-result)"'
alias .='pwd'
alias ..='cd ..'
alias ...='cd ../..'
## Sudo shortcuts
if [ $UID -ne 0 ]; then
alias svim='sudo -e'
alias root='sudo su'
alias scat='sudo cat'
alias reboot='sudo systemctl reboot'
alias poweroff='sudo systemctl poweroff'
alias netctl='sudo netctl'
fi
## Defaults
alias tmux='tmux -2'
alias mosh='mosh --no-init'
alias mkdir='mkdir -p'
alias grep='grep --color=auto'
alias more='less'
alias diff='colordiff' # requires colordiff package
alias info='info --vi-keys'
alias ping='ping -c 5' # ping 5 times
alias feh='feh -.'
## Corrections
alias cd..='cd ..'
## Directory sizes
alias du1='du --max-depth=1'
## Search
### -recursively
alias ff='find . -name $*'
### -in commands history
alias hist='history | grep' # requires an argument
### -for a process
alias pgg='ps -Af | grep' # requires an argument
## >ls
alias lr='ls -R' # recursive ls
alias la='ll -a'
### sudo ls
alias sls='sudo ls -hF --color=auto'
alias sll='sudo ls -hFl --color=auto'
alias sll='sudo ls -hFla --color=auto'
## >yay/pacman
(( $+commands[yay] )) && package_manager='yay' || package_manager='sudo pacman'
alias y=" $package_manager" # default action - yay
alias ys=" $package_manager -S" # '[s]ync' - install one or more packages
alias yu=" $package_manager -Syu" # '[u]pdate' - upgrade all packages to their newest version
alias yua="$package_manager -Syua" # '[u]pdate with [aur]'- upgrade all packages to their newest version + aur
alias yr=" $package_manager -Rs" # '[r]emove' - uninstall one or more packages
alias yc=" $package_manager -Scc" # '[c]lean cache' - delete all not currently installed package files
alias yss="$package_manager -Ss" # '[Ss]earch' - search for a package using one or more keywords
alias yi=" $package_manager -Si" # '[i]nfo' - show information about a package
alias ylo="$package_manager -Qdt" # '[l]ist [o]rphans' - list all packages which are orphaned
alias ylf="$package_manager -Ql" # '[l]ist [f]iles' - list all files installed by a given package
### [yref]resh: Use Reflector to populate mirrorlist with fastest mirrors
alias yref="sudo reflector --verbose --sort rate -c BE,CZ,DK,EE,FI,LT,NL,NO,PL,LV --protocol https --completion-percent 80 --save /etc/pacman.d/mirrorlist --download-timeout 60"
### Remove pacman lock file
alias yunlock="sudo rm /var/lib/pacman/db.lck"
### Latest installed packages
alias ylatest="expac --timefmt='%F %T' '%l %n' | sort -n | less"
## >systemctl
alias sy="sudo systemctl"
alias sys="sudo systemctl start"
alias sysp="sudo systemctl stop"
alias syst="sudo systemctl status"
alias syr="sudo systemctl restart"
alias sye="sudo systemctl enable"
alias syd="sudo systemctl disable"
alias sydr="sudo systemctl daemon-reload"
# >> user services
alias suu="systemctl --user"
alias sus="systemctl --user start"
alias susp="systemctl --user stop"
alias sust="systemctl --user status"
alias sur="systemctl --user restart"
alias sue="systemctl --user enable"
alias sud="systemctl --user disable"
alias sudr="systemctl daemon-reload"
## >Python
# Virtual environment aliases
alias venvc="python3 -m venv venv"
alias venvcreate="python3 -m venv venv"
alias venva="source venv/bin/activate"
alias venvactivate="source venv/bin/activate"
alias venvi="python3 -m pip install --user virtualenv"
alias venvinstall="python3 -m pip install --user virtualenv"
alias venvd="deactivate"
# Dependency / `pip` aliases
alias pipi="pip install"
alias pipu="pip uninstall"
alias pipl="pip list"
alias pipf="pip freeze > requirements.txt"
alias pipr="pip install -r requirements.txt"
## >xclip
alias xc='xclip -selection clipboard' # copy to clipboard, ctrl+c, ctrl+shift+c
alias xcp='xclip -selection clipboard -o' # paste from clipboard, ctrl+v, ctrl+shift+v
alias xcs='xclip -selection primary -o' # paste from highlight, middle click, shift+insert
## >tig
alias t="git show | tig"
## >btop
alias b="btop"
# >vyprvpn
alias vv="vyprvpn"
alias vvr="vyprvpn refresh"
alias vvc="vyprvpn connect"
alias vvd="vyprvpn disconnect"
alias vvs="vyprvpn server" # [show | set | list]
alias vvp="vyprvpn protocol" # [show | set | list]
# >nordvpn
# alias nv="nordvpn"
# alias nvc="nordvpn c"
# alias nvs="nordvpn status"
# alias nvce="nordvpn c Estonia"
# alias nvcd="nordvpn c Double_VPN"
# alias nvco="nordvpn c Onion_Over_VPN"
# alias nvd="nordvpn disconnect"
# >gcalcli
alias c="gcalcli"
alias cw="gcalcli calw"
alias cm="gcalcli calm"
alias ca="gcalcli agenda"
alias cl="gcalcli list"
alias cld="gcalcli delete"
alias clc="gcalcli quick"
alias clr="gcalcli remind"
# ...
alias bdays="gcalcli --calendar 'Facebook Birthdays' calw"
alias bdaysm="gcalcli --calendar 'Facebook Birthdays' calm"
# >archtorify
alias at="sudo archtorify"
alias att="sudo archtorify -t"
alias atr="sudo archtorify --restart"
alias atc="sudo archtorify -c"
# >torsocks
alias socksoff="source torsocks off"
alias sockson="source torsocks on"
## >speedtest
alias st="speedtest-cli --no-upload --single --bytes"
alias stogre="speedtest-cli --no-upload --single --bytes --server 22608"
## >journalctl
jr() { jct "-r" }
# Functions & custtom aliases (simple, mostly for restarting)
## ~Get my ip
alias myip="curl ipinfo.io/ip"
alias myipi="curl ipinfo.io"
alias myipinfo="curl ipinfo.io"
## >zsh
function erc { $EDITOR ~/.zshrc; rerc }
function eprc { $EDITOR ~/.p10k.zsh; rerc }
function rerc { source ~/.zshrc }
## >polybar
function epoly { $EDITOR ~/.config/polybar/cuts/config.ini; repoly }
function repoly { pkill polybar; source ~/.config/polybar/cuts/launch.sh }
## >picom
function epicom { $EDITOR ~/.config/picom.conf; repicom }
function repicom { pkill picom; sleep 1; picom -b }
## > tmux
alias retmux="source-file ~/.tmux.conf"
## >pacman
function repacman { sudo rm /var/lib/pacman/db.lck; }
## >pulseaudio
function repulse { pulseaudio -k && pulseaudio --start }
## >psmouse
function remouse { sudo modprobe -r psmouse; sudo modprobe psmouse; }
## >xneur
function rexneur { pkill xneur && xneur & }
## >pam_usb
function repam { rm -rf ~/.pamusb; pamusb-check --debug $USER; }
# Functions (more complex)
# -Open [f]ile manager in cwd, optional repeat count
f() {
for i in {1..${1:=1}};
do nohup thunar . >/dev/null 2>&1&;
done
}
# -Open [n]ew [t]erminal in cwd, optional repeat count
nt() {
for i in {1..${1:=1}};
do nohup $TERM >/dev/null 2>&1&;
done
}
# -[c]opy via [rs]ync
cr() {
rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 "$@"
}
# -[m]ove via [rs]ync
mr() {
rsync --archive -hh --partial --info=stats1,progress2 --modify-window=1 --remove-source-files "$@"
}
# FINISH
zstyle :compinstall filename '/home/dmitriy/.zshrc'
# Launch tmux by default
# [[ -z "$TMUX" ]] && tmux new
# PROFILING
### set the trace prompt to include seconds, nanoseconds, script name and line number
#zmodload zsh/datetime
#setopt promptsubst
#PS4='+$EPOCHREALTIME %N:%i> '
### save file stderr to file descriptor 3 and redirect stderr (including trace
### output) to a file with the script's PID as an extension
#exec 3>&2 2>/tmp/startlog.$$
### set options to turn on tracing and expansion of commands contained in the prompt
#setopt xtrace prompt_subst
#
### turn off tracing
#unsetopt xtrace
### restore stderr to the value saved in FD 3
#exec 2>&3 3>&-