/
.zshrc
executable file
·562 lines (431 loc) · 17 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
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
550
551
552
553
554
555
556
557
558
559
560
561
562
#!/usr/bin/env bash
# TODO add notes up here with links to zsh-managment docs
# enable profiling
# zmodload zsh/zprof
################################################################################
# Environment Vars
################################################################################
# export EDITOR='emacsclient -nw'
# export VISUAL='emacsclient -nw'
export EDITOR='nvim'
export VISUAL='nvim'
export PAGER='less'
export RANGER_LOAD_DEFAULT_RC=FALSE
export FONTCONFIG_PATH='/etc/fonts'
alias 'zz'='source ~/.zshrc'
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
# Antidote ################################################################################
if [ -f /usr/share/zsh-antidote/antidote.zsh ]; then
source '/usr/share/zsh-antidote/antidote.zsh'
antidote load
elif [ -f /opt/homebrew/opt/antidote/share/antidote/antidote.zsh ]; then
source /opt/homebrew/opt/antidote/share/antidote/antidote.zsh
antidote load
fi
if type brew &>/dev/null
then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
fi
# enable completion features
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit -i
# allow .hidden file tab completion
setopt globdots
# required to find some shared libs
export LD_LIBRARY_PATH=/usr/local/lib
################################################################################
# Keychain
################################################################################
# keychain for ssh and gpg
if hash keychain 2>/dev/null; then
keychain_path="~/.keychain/$(hostname)-sh-gpg"; # this file won't exist if keychain isn't running
if [ -f "$keychain_path" ]; then
. $keychain_path;
else
case "$OSTYPE" in
darwin*)
eval $(keychain --agents gpg,ssh --eval --noask)
;;
linux*)
eval $(keychain --agents gpg,ssh --eval --systemd --noask)
;;
esac
fi;
fi
################################################################################
# Theme/Style
################################################################################
# Restore pywal colors
# ~/.nix-profile/bin/wal -Rq
alias wa='wal -Req'
alias ns='nix-shell'
################################################################################
# vim-mode
################################################################################
export KEYTIMEOUT=1
to-tmux-copy-mode() {
tmux copy-mode
tmux send-keys "k"
}
autoload to-tmux-copy-mode
zle -N to-tmux-copy-mode
ctrl-r() {
tmux send-keys "i"
tmux send-keys "C-r"
}
autoload ctrl-r
zle -N ctrl-r
to-insert-mode() {
tmux send-keys "i"
}
autoload to-insert-mode
zle -N to-insert-mode
page-up() {
tmux copy-mode
tmux send-keys "C-u"
}
autoload page-up
zle -N page-up
search-page() {
tmux copy-mode
tmux send-keys "/"
}
autoload search-page
zle -N search-page
search-page-up() {
tmux copy-mode
tmux send-keys "?"
}
autoload search-page-up
zle -N search-page-up
my-paste() {
xclip -o
}
autoload my-paste
zle -N my-paste
choose-session() {
tmux choose-session
}
autoload choose-session
zle -N choose-session
bindkey -M vicmd 'k' to-tmux-copy-mode \
'q' to-insert-mode \
'\e' to-insert-mode \
'^r' ctrl-r \
'/' search-page \
'?' search-page-up \
'p' my-paste \
'-' choose-session
################################################################################
# Gcloud
################################################################################
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/home/russ/google-cloud-sdk/path.zsh.inc' ]; then
source '/home/russ/google-cloud-sdk/path.zsh.inc';
fi
# The next line enables shell command completion for gcloud.
if [ -f '/home/russ/google-cloud-sdk/completion.zsh.inc' ]; then
source '/home/russ/google-cloud-sdk/completion.zsh.inc';
fi
if [ -f "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc" ]; then
source "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc";
fi
if [ -f "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc" ]; then
source "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc";
fi
export HOMEBREW_NO_AUTO_UPDATE=1
################################################################################
# Fzf
################################################################################
[ -f /usr/bin/fzf ] &&
source /usr/share/fzf/completion.zsh
[ -f /usr/bin/fzf ] &&
source /usr/share/fzf/key-bindings.zsh
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
[ -f /usr/bin/fzf ] && source ~/.zsh/fzf.zsh
source ~/.zsh/fuzzy-sys.zsh
################################################################################
# Color fix
################################################################################
setopt PROMPT_SUBST
export RPROMPT='%@'
################################################################################
# Tmux
################################################################################
source ~/dotfiles/zsh/tmux.sh
################################################################################
# Misc Aliases
################################################################################
alias vim=nvim
alias vi=nvim
alias ls=eza
alias l='ls -lha'
alias cat=bat
alias e='emacs -nw'
alias ':q'='exit'
################################################################################
# Docker
################################################################################
alias d=docker
alias dps='docker ps'
alias dpsa='docker ps -a'
alias drm='docker rm'
alias drmi='docker rmi'
alias drit='docker run -it'
alias drd='docker run -d'
alias di='docker images'
alias dc='docker-compose'
alias dcr='docker-compose restart'
alias dcud='docker-compose up -d'
alias dcub='docker-compose up -d --build'
alias dcl='docker-compose logs'
# unalias dclf
function dclf() {
docker-compose logs -f "$@" | cut -f2- -d'|'
}
function dcrf() {
docker-compose restart "$@"
docker-compose logs -f "$@" | cut -f2- -d'|'
}
alias dcps='dc ps'
################################################################################
# Kubernetes
################################################################################
alias kc='kubectl'
alias kca='kubectl --all-namespaces'
alias kcd='kubectl --namespace=default'
alias kg='kubectl get'
alias kpods='kubectl get pods'
alias kpodsa='kubectl get pods --all-namespaces'
alias kings='kubectl get ing'
alias kingsa='kubectl get pods --all-namespaces'
alias kdeploys='kubectl get deployments'
alias kdns='kubectl get ing'
alias kedit='kubectl edit deployments ' # the trailing space is intentional
alias kt='kubetail'
################################################################################
# Git
################################################################################
alias gday='git log --name-only --since=yesterday.midnight --until=today.midnight --author="$(git config --get user.email)"'
alias glp="git log --graph --pretty=format:'%Cred%h%Creset -%Cblue %an %Creset - %C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
alias gprom="git pull --rebase origin master"
alias gcan='git commit --amend --no-edit'
alias gcam='gc --amend'
alias gpf='git push --force-with-lease'
alias gpff='git push --force-with-lease --no-verify' # aka git push f***ing force
alias gds='git diff --staged'
alias gfx='git commit --fixup'
alias gri='git rebase -i --autosquash'
alias grim='git rebase -i --autosquash master'
alias gbm='git branch --merged'
alias gwip="git commit -m 'wip'"
alias pulls='open "https://github.com:/$(git remote -v | command ggrep -oP "'"(?<=git@github.com:).+(?=\.git)"'" | head -n 1)/pulls"'
alias git=hub
alias gpr='git pull-request'
alias gpo='git push -u origin'
alias gpob='git push -u origin "$(git symbolic-ref --short HEAD)"'
alias gcom='gco master'
alias gclone='hub clone'
# list recent branches
# thanks: https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
function br() {
git for-each-ref --count=5 --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
}
alias cwb='git symbolic-ref --short HEAD'
alias gwip="git commit -m 'wip'"
alias delete-merged-branches="git checkout master && git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"
# from jskrzypek
# alias is-unmerged="! f() { local branch=$(git rev-parse --abbrev-ref ${1-HEAD}) ; local base=${2-master} ; echo $(git cherry $base $(git commit-tree $(git rev-parse $branch^{tree}) -p $(git merge-base $base $branch) -m _) | cut -f1 -d' ') $branch; }; f"
alias branch-merged="! f() { git for-each-ref refs/heads/ '--format=%(refname:short)' | xargs -I {} git is-unmerged {} ${1-master} | grep -E '^-' | cut -f2 -d' ' ; }; f"
alias clean-merged-branches="!f() { git checkout -q ${1-master} && git branch-merged ${1-master} | xargs -n1 -p git branch -D; }; f"
################################################################################
# Systemctl
################################################################################
case "$OSTYPE" in
linux*)
alias sc='systemctl'
alias scr='systemctl restart'
alias scs='systemctl status'
alias jc='journalctl'
esac
################################################################################
# Misc
################################################################################
alias jk='bat ./readme.org'
alias nf='neofetch'
alias pd='pandoc'
source ~/.zsh/grfn.zsh-theme
################################################################################
# Haskell
################################################################################
function stack-watch-test-path() {
pattern="${1:-}"
ghcid -c "stack ghci grid:lib grid:grid-test --ghci-options=-fobject-code" \
--height=$(tput lines) --width=$(tput cols) \
--warnings --test "${pattern}" \
| source-highlight -s haskell -f esc
}
alias swtp='stack-watch-test-path'
################################################################################
# Node
################################################################################
export NVM_DIR="$HOME/.nvm"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # faster zsh startup
# function loadnvm() {
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # call when you want it
# }
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
################################################################################
# Rust
################################################################################
export PATH="$HOME/.cargo/bin:$PATH"
alias ps=procs
alias du=dua
################################################################################
# Doom emacs
################################################################################
export PATH="$HOME/.config/emacs/bin:$PATH"
# Added by n-install (see http://git.io/n-install-repo).
export N_PREFIX="$HOME/n"; [[ :$PATH: == *":$N_PREFIX/bin:"* ]] || PATH+=":$N_PREFIX/bin"
################################################################################
# misc
################################################################################
# unalias 'sp'
################################################################################
# Lua
################################################################################
function useluaver() {
[ -s ~/.luaver/luaver ] && . ~/.luaver/luaver
}
################################################################################
# Delete from history via fzf
################################################################################
# https://superuser.com/questions/1316668/zsh-bash-delete-specific-lines-from-history
function delete-command () {
# Prevent the specified history line from being saved.
local HISTORY_IGNORE="${(b)$(fc -ln $1 $1)}"
# Write out the history to file, excluding lines that match `$HISTORY_IGNORE`.
fc -W
# Dispose of the current history and read the new history from file.
fc -p "$HISTFILE" "$HISTSIZE" "$SAVEHIST"
# TA-DA!
print "Deleted '$HISTORY_IGNORE' from history."
}
function pick_from_history () {
history | fzf --tac --tiebreak=index | perl -ne 'm/^\s*([0-9]+)/ and print "$1"'
}
function delete_from_history () {
delete-command "$(pick_from_history)"
}
################################################################################
# Ruby
################################################################################
export PATH="$HOME/.gem/ruby/2.7.0/bin:$PATH"
eval "$(direnv hook zsh)"
################################################################################
# git summary
################################################################################
#[[file:~/MirkoLedda/git-summary/README.md::git-summary][local git-summary readme]]
alias git-summary='~/MirkoLedda/git-summary/git-summary'
################################################################################
# babashka
################################################################################
_bb_tasks() {
local matches=(`bb tasks |tail -n +3 |cut -f1 -d ' '`)
compadd -a matches
_files # autocomplete filenames as well
}
compdef _bb_tasks bb
export PATH="$PATH:$HOME/.babashka/bbin/bin"
################################################################################
# Python
################################################################################
# already on path to due to .zshenv
if (( $+commands[pyenv] )); then
eval "$(pyenv init -)";
eval "$(pyenv virtualenv-init -)";
test ! -f ~/.pyenv/version && pyenv global system;
fi
################################################################################
# perf
################################################################################
timezsh() {
local shell=${1-$SHELL}
for i in $(seq 1 10); do time $shell -i -c exit; done
}
# print profiling
# zprof
################################################################################
# aseprite
################################################################################
PATH=$PATH:~/.local/share/Steam/steamapps/common/Aseprite
case "$OSTYPE" in
darwin*)
alias aseprite=~/Library/Application\\\ Support/Steam/steamapps/common/Aseprite/Aseprite.app/Contents/MacOS/aseprite
esac
################################################################################
# godot
################################################################################
# gut without window
alias gut='godot --headless --path . -d -s addons/gut/gut_cmdln.gd'
# gut with window
alias gutw='godot --path . -d -s addons/gut/gut_cmdln.gd'
case "$OSTYPE" in
darwin*)
alias godotsteam='~/.local/share/godotsteam/GodotEditor.app/Contents/MacOS/godot'
;;
linux*)
alias godotsteam='~/.local/share/godotsteam/linux-421-editor.x86_64'
;;
esac
#########################################################################
# osx
#########################################################################
case "$OSTYPE" in
darwin*)
# gls in emacs
PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"
# java for clojure/babashka
PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
# homebrew
alias b="brew"
alias bs="brew services"
alias bsr="brew services restart"
alias bsl="brew services list"
alias bi="brew install"
alias bu="brew uninstall"
alias binf="brew info"
# autojump
[ -f /opt/homebrew/etc/profile.d/autojump.sh ] && . /opt/homebrew/etc/profile.d/autojump.sh
esac
#########################################################################
# clawe
#########################################################################
alias clawebb='bb --config ~/russmatney/clawe/bb.edn'
alias clawebb_ls='clawebb -x clawe.debug/ls-print --type'
alias clawebb_ls_clients='clawebb -x clawe.debug/ls-clients'
alias clawebb_ls_workspaces='clawebb -x clawe.debug/ls-workspaces'
alias clawebb_toggle='clawebb -x clawe.toggle/toggle --key'
alias clawebb_reload='clawebb -x clawe.restart/reload'
alias clawebb_mx='clawebb -x clawe.mx/mx'
alias clawebb_mx_fast='clawebb -x clawe.mx/mx-fast'
alias dinobb='bb --config ~/russmatney/dino/bb.edn'
#########################################################################
# itch.io
#########################################################################
# https://itch.io/docs/butler/pushing.html#appendix-b-beeps-4-life
# alias butler='~/.config/itch/apps/butler/butler --beeps4life'
case "$OSTYPE" in
darwin*)
export PATH="$PATH:$HOME/Library/Application Support/itch/apps/butler"
;;
linux*)
export PATH="$PATH:$HOME/.config/itch/apps/butler"
;;
esac
# atuin #########################################################################
eval "$(atuin init zsh)"
# dotnet #########################################################################
export PATH="$PATH:$HOME/.dotnet/tools"