-
Notifications
You must be signed in to change notification settings - Fork 0
/
_zshrc
579 lines (508 loc) · 16.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
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
#########
# Antigen
#########
source $HOME/.antigen/antigen.zsh
antigen use oh-my-zsh
export NVM_LAZY_LOAD=true
export NVM_LAZY_LOAD_EXTRA_COMMANDS=('vim' 'nvim')
antigen bundles <<EOBUNDLES
# node version manager
lukechilds/zsh-nvm
# oh-my-zsh plugins
archlinux
colored-man-pages
extract
git
gpg-agent
npm
python
stack
systemd
vi-mode
zsh-users/zsh-completions src
zsh-users/zsh-history-substring-search
# Fish-like command coloring - this needs to be the last bundle
zsh-users/zsh-syntax-highlighting
# Use zsh for nix-shell
chisui/zsh-nix-shell
EOBUNDLES
antigen theme prikhi/molokai-powerline-zsh molokai-powerline
antigen apply
# Modules
autoload -U zcalc
autoload -U compinit && compinit
autoload -U +X bashcompinit && bashcompinit
# Options
zstyle ':completion:*' menu select
# Allow completions for commands to apply to their aliases as well
unsetopt COMPLETE_ALIASES
# Wait 10 seconds before allowing globbed deletes
setopt RM_STAR_WAIT
# Allow background jobs to continue on exit
setopt AUTO_CONTINUE
# Enable recursive & negation globbing
setopt EXTENDED_GLOB
# Allow file completions for all command flags
setopt MAGIC_EQUAL_SUBST
#########################
# Environmental Variables
#########################
# Use neovim but fallback to vim if not isn't installed
if type "nvim" > /dev/null; then
export EDITOR="nvim"
export DIFFPROG="nvim -d"
else
export EDITOR="vim"
fi
export PAGER="less"
export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
export LESS="-R"
export VBOX_USB=usbfs
export PATH="$HOME/.ghcup/bin:$HOME/.local/bin:$HOME/.bin:$HOME/.cargo/bin:$PATH"
export NNTPSERVER="news.gmane.org"
export CCACHE_DIR=/tmp/ccache
export LEDGER_FILE="${HOME}/Documents/accounting/2024.journal"
export ZK_NOTEBOOK_DIR="${HOME}/z/"
export HISTSIZE=1000000000
export SAVEHIST=${HISTSIZE}
#########
# Aliases
#########
# Vim shortcuts
alias v="$EDITOR"
alias vd="vimdiff"
alias sv="EDITOR=vim sudoedit"
alias svd="EDITOR=vimdiff sudoedit"
alias svim="EDITOR=vim sudoedit"
alias svimdiff="EDITOR=vimdiff sudoedit"
alias s="sudo"
alias o="xdg-open"
alias ra="ranger"
alias zc="zcalc"
alias am="alsamixer"
alias sz="source ~/.zshrc"
alias rs="rsync -avhz --progress"
alias yt='yt-dlp -a vids.txt'
alias srv="python -m http.server"
alias hkl="hklaunch"
alias ldg='hledger'
alias open="xdg-open"
alias wine32="WINEPREFIX=~/.wine32 WINEARCH=win32 wine"
alias xpaste="xsel --clipboard --output"
alias mpaste='mpv $(xpaste)'
alias ytpaste='yt-dlp $(xpaste)'
alias xget='wget $(xpaste)'
alias fpaste='xget -O - | feh -'
alias xclass='echo "WM_CLASS(STRING) = \"NAME\", \"CLASS\"" && xprop | grep "WM_CLASS"'
# Edit config files
alias zshrc="v ~/.zshrc"
alias vimrc="v ~/.vimrc"
alias awesomerc="v ~/.config/awesome/rc.lua"
alias awrc="awesomerc"
alias xmonadrc="cd ~/.config/xmonad/; v src/Config.hs"
alias xmrc="xmonadrc"
alias xmrcd="cd ~/.config/xmonad/"
alias pentarc="v ~/.pentadactylrc"
alias dfiles="cd ~/.dotfiles"
alias notes="cd ~/Documents/Notes"
alias ideas="v ~/Projects/ideas.rst"
alias acct="cd ~/Documents/accounting/"
# SSH
alias vps="ssh [email protected] -i ~/.ssh/id_ecdsa"
# Safety First!
alias rm="rm -i"
alias mv="mv -i"
alias cp="cp -i"
# Arch linux networking - netctl
alias nc-start="sudo netctl start"
alias nc-stop="sudo netctl stop"
alias nc-restart="sudo netctl restart"
alias nc-status="sudo netctl status"
alias wifi-menu="sudo wifi-menu && sudo mount -a"
# Udevil Mounting
alias udm="udevil mount"
alias udum="udevil unmount"
function udevil-umount-all() {
for f in /media/smb-*; do
udevil unmount "$f"
done
}
# SystemD User Commands
alias sc="sudo systemctl"
alias scu="systemctl --user"
alias scu-start="systemctl --user start"
alias scu-stop="systemctl --user stop"
alias scu-restart="systemctl --user restart"
alias scu-status="systemctl --user status"
alias scu-enable="systemctl --user enable"
alias scu-disable="systemctl --user disable"
alias jc="sudo journalctl"
alias jcu="journalctl --user"
# Arch linux package management - yay/pacman
# Only download new packages, do not install them
alias pacdow='sudo pacman -Syuw'
# Synchronize with repositories before upgrading packages that are out of date
# on the local system.
alias pacupg='yay -Syu --devel'
# Install specific package(s) from the repositories
alias pacin='yay -S'
# Install packages as dependencies instead of explicitly
alias pacind='sudo pacman -S --asdeps'
# Display information about a given package in the repositories
alias pacrep='yay -Si'
# Search for package(s) in the repositories
alias pacreps='yay -Ss'
# Search for packages containing a file
alias pacfs='pacman -F'
# Update the file database
alias pacfu='sudo pacman -Fy'
# Pull the git repository for a package from the AUR
function aur-clone() {
cd "$HOME/Projects/AUR/"
if [ ! -d "$1/.git" ]; then
git clone "ssh://[email protected]/$1.git"
fi
cd "$1/"
}
# Git
alias gm='git merge'
alias grb='git rebase'
alias gpft='git push --follow-tags'
# Docker
alias dcub='docker compose up --build'
# Prettify JSON: cat x.json | pretty_json
alias pretty_json='python -m json.tool'
# Install applications from Haskell Stack - needs to be done when global stack
# LTS is updated
alias stack_install_apps='stack install -j8 --ghc-options=-O2 hoogle ghcid brittany hlint implicit-hie'
# Install global NPM applications
alias npm_install_apps='npm i -g prettier sass-lint stylelint elm elm-test elm-analyse @elm-tooling/elm-language-server elm-format elm-json npm-check-updates purescript purescript-language-server purty purs-tidy'
# Install development AUR packages
function pacman_install_dev() {
yay -S --noconfirm $(pacman -Qqe | grep -E '\-(git)')
}
# Selenium & Xvfb for headless integration testing
# Create a virtual screen on display :20 (Virtual Frame Buffer)
alias vfb='sudo Xvfb :20 -ac'
alias selenium='DISPLAY=:20 java -jar /usr/share/selenium-server/selenium-server-standalone.jar -timeout=60 -browserTimeout=60'
alias seleniumlocal='DISPLAY=:0 java -jar /usr/share/selenium-server/selenium-server-standalone.jar -timeout=60 -browserTimeout=60'
# Haskell package development/management - cabal
# These use multiple cores
alias cbj='cabal -j'
alias cbb='cbj build'
alias cbi='cbj install'
alias cbc='cabal clean'
alias cbh='cabal haddock --all'
alias cbt='cabal test -j'
alias hspec='cbt --show-details=always --test-option=--color --test-option=--fail-fast'
alias tasty='cbt --show-details=always --test-option=--color=always'
alias fcbb='cbc && cbb && cbh' # A full Clean + Build (including docs)
# Pretty much switched to stack so the above can probably be removed
alias sr='stack repl'
alias sb='stack build'
alias st='stack test'
alias sbfw='stack build --file-watch'
alias stfw='stack build --test --file-watch'
# Use readline with the SML/NJ REPL
alias sml='rlwrap sml'
alias erepl='rlwrap elm repl'
# C development
alias c="gcc -g -O2 -Wall -Wextra -Werror --std=c11 -pedantic \
-Wno-unused-parameter -Wfloat-equal -Wundef -Wshadow \
-Wpointer-arith -Wcast-align -Wstrict-prototypes \
-Wstrict-overflow=5 -Wwrite-strings -Waggregate-return \
-Wswitch-enum -Wconversion -Wunreachable-code -Wformat=2 \
-Winit-self \
-ftrapv -fverbose-asm \
-D_XOPEN_SOURCE=700"
alias smi='sudo make install'
alias mmc='make maintainer-clean'
alias auconf='./autogen.sh && ./configure --bindir /usr/bin --datadir /usr/share --sysconfdir /etc'
alias aumake='auconf && make'
alias auinstall='auconf && make && sudo make install'
# Make
alias m='make'
alias mw='make watch'
alias mt='make test'
# Redmine CLI Client - hkredmine
# Show Issues w/ Project as 1st position argument
alias hkpi='hkredmine issues -S priority:desc,category -p'
# New Issue w/ Project as 1st position argument & open description in editor
alias hkni='hkredmine newissue -e -p'
# Others
alias hkr='hkredmine'
alias hkru='hkredmine use'
alias hkri='hkredmine issue'
alias hkris='hkredmine issues'
alias hkup='hkredmine update'
alias hkcl='hkredmine close'
alias hkca='hkredmine categories'
alias hknc='hkredmine newcategory'
alias hkve='hkredmine version'
alias hkvs='hkredmine versions'
alias hknv='hkredmine nextversion -S priority:desc,category'
alias hkst='hkredmine startwork'
alias hkrp='hkredmine pause'
alias hkrr='hkredmine resume'
alias hkstop='hkredmine stopwork'
# smos & intray - Getting Things Done
alias tasks='smos ~/.tasks/general.smos'
alias taskd='cd ~/.tasks/'
alias smosd='cd ~/.tasks/'
alias in='intray add'
alias isize='intray size'
alias review='intray review'
alias sq='smos-query'
alias next='smos-query next'
alias waiting='smos-query waiting'
alias agenda='smos-query agenda --all-time --month-block'
alias projects='smos-query projects'
alias ssync='smos-sync-client sync'
alias isync='intray sync'
alias install_smos='stack install --ghc-options='"'"'-O2 -threaded'"'"' :smos :smos-archive :smos-query :smos-scheduler :smos-single :smos-sync-client'
# start a new smos project file with a single task
function smosnp() {
PROJECT_FILE="$1"
FULL_PATH="${HOME}/.tasks/projects/${PROJECT_FILE}"
PROJECT_DIR="$(dirname ${FULL_PATH})"
TASK="${@:2}"
if [ ! -e "${FULL_PATH}" ]; then
smos-single ${TASK} --file "projects/${PROJECT_FILE}"
fi
smos "${FULL_PATH}"
}
function _smosnp() {
_arguments "1:directory:_path_files -/ -W \"${HOME}/.tasks/projects/\""
}
compdef _smosnp smosnp
# open the given project file in smos
function smosp() {
PROJECT_FILE="$1"
FULL_PATH="${HOME}/.tasks/projects/${PROJECT_FILE}"
smos "${FULL_PATH}"
}
function _smosp() {
_arguments "1:file:_path_files -W \"${HOME}/.tasks/projects/\""
}
compdef _smosp smosp
# open the given task file in smos
function task() {
TASK_FILE="$1"
FULL_PATH="${HOME}/.tasks/${TASK_FILE}"
smos "${FULL_PATH}"
}
# archive the given task file
function archive() {
TASK_FILE="$1"
FULL_PATH="${HOME}/.tasks/${TASK_FILE}"
smos-archive "${FULL_PATH}"
}
# edit a smos task in vim
function vt() {
TASK_FILE="$1"
FULL_PATH="${HOME}/.tasks/${TASK_FILE}"
$EDITOR "${FULL_PATH}"
}
function _smos_comp_tasks() {
_arguments "1:file:_files -W \"${HOME}/.tasks/\""
}
compdef _smos_comp_tasks task archive vt
# Show the next 2 weeks worth of reminders
alias rlist='rem -s+2 | cut -d " " -f 1,6-'
# Translate
alias french='dict -d fd-fra-eng'
# ls colors
if [ -f ~/.dir_colors ]; then
eval `dircolors ~/.dir_colors`
fi
# Python2 virtualenvwrapper setup
export VIRTUALENVWRAPPER_PYTHON="/usr/bin/python2.7"
if [ -f "/usr/bin/virtualenvwrapper.sh" ]; then
source /usr/bin/virtualenvwrapper.sh
elif [ -f "/etc/bash_completion.d/virtualenvwrapper" ]; then
source /etc/bash_completion.d/virtualenvwrapper
fi
# Nix
# Set the default <nix-pkgs> if we have a local repository.
if [ -d "${HOME}/.nix-defexpr/" ]; then
export NIXPKGS="${HOME}/.nix-defexpr/"
fi
# Load our user's nix profile if it exists.
if [ -f "${HOME}/.nix-profile/etc/profile.d/nix.sh" ]; then
source "${HOME}/.nix-profile/etc/profile.d/nix.sh"
fi
# Setup zsh history substring search plugin
# bind UP and DOWN arrow keys
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
# bind k and j for VI mode
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
# ALL HAIL THE HYPNOTOAD
if [ -e "/usr/bin/fortune" -a -e "/usr/bin/cowsay" ]; then
fortune -a | cowsay -f hypnotoad -n
fi
# Enable custom completions
for f in $HOME/.completions/*; do
source $f
done
complete -o bashdefault -F _hkredmine hkr
# Fix Stack Completions
unfunction _stack
if [ -x "$(which stack)" ]; then
eval "$(stack --bash-completion-script stack)"
fi
# Enable ArchLiux command-not-found
if [ -f "/usr/share/doc/pkgfile/command-not-found.zsh" ]; then
source "/usr/share/doc/pkgfile/command-not-found.zsh"
fi
# Load Accounting Aliases
if [ -f "$(dirname ${LEDGER_FILE})/.zshrc" ]; then
source "$(dirname ${LEDGER_FILE})/.zshrc"
fi
###########
# Functions
###########
# For things in `~/.config`. If `$1` is a directory, cd into it. If `$1` is a
# file, cd into it's directory & open it in vim. If doesn't exist, creating,
# assuming `$1` is a file.
# TODO: if doesn't exist, prompt if file or directory & handle appropriately
function cfg() {
DEST="${1}"
FULL_DEST="${HOME}/.config/${DEST}"
if [[ -d "${FULL_DEST}" ]]; then
if [[ ! -e "${FULL_DEST}" ]]; then
mkdir -p "${FULL_DEST}"
fi
cd "${FULL_DEST}"
else
BASE_DIR="$(dirname ${FULL_DEST})"
FILE_NAME="$(basename ${DEST})"
if [[ ! -e "${BASE_DIR}" ]]; then
mkdir -p "${BASE_DIR}"
fi
cd "${BASE_DIR}"
${EDITOR} ${FILE_NAME}
fi
}
function _cfg() {
_arguments "1:file:_path_files -W \"${HOME}/.config/\""
}
compdef _cfg cfg
# Enter a coding directory - either `~/code/` or `~/Projects/`
function prj() {
local DEST="${1}"
local PREFIX=""
if [[ -d "${HOME}/Projects" ]]; then
PREFIX="Projects"
else;
PREFIX="code"
fi
cd "${HOME}/${PREFIX}/${DEST}"
}
function _prj() {
#_arguments "1:directory:_path_files -/ -W \"${HOME}/.tasks/projects/\""
if [[ -d "${HOME}/Projects" ]]; then
_arguments "1:directory:_path_files -/ -W \"${HOME}/Projects\""
else
_arguments "1:directory:_path_files -/ -W \"${HOME}/code\""
fi
}
compdef _prj prj
# Make the .SRCINFO file for an AUR package
function mksrcinfo() {
makepkg --printsrcinfo > .SRCINFO
}
# Copy rxvt-unicode-256color terminfo to specified remote host
function push_rxvt_info () {
infocmp rxvt-unicode-256color | ssh $1 "mkdir -p .terminfo && cat >/tmp/ti && tic /tmp/ti"
}
# Restore the `$2` MySQL bzip2 dump to the `$1` database.
function mysql_restore_bz2 () {
bunzip2 < "$2" | mysql -u root -p "$1"
}
# Run `make build`, and run `$1` if successful. Afterwards, watch the `$2`
# directory for changes and repeat.
function buildRunWatchKill () {
PROGRAM="${1}"
WATCH_DIR="${2}"
while true; do
PID=""
make build
if [ $? -eq 0 ] ; then
echo "OK"
if [ "$PROGRAM" ] ; then
$PROGRAM &
PID="$!"
sleep 0.1
fi
else
echo "FAIL"
fi
inotifywait -q -q -r -e 'close_write' $WATCH_DIR
echo "CHANGED"
if [ "$PID" ] ; then
kill $PID
fi
echo "AGAIN"
done
}
# List the Video Resolution & Audio Channels of the File(s)
function avinfo {
mediainfo "${@}" | grep -E '(pixels|channels)'
}
function cmp_mediainfo {
vimdiff =(mediainfo "${1}") =(mediainfo "${2}")
}
## Bindings
# Bind Ctrl-R to History Search
bindkey '^R' history-incremental-pattern-search-backward
# Bind Ctrl-W to Delete Word Backwards
bindkey '^W' backward-kill-word
# Bind ;; & jj to Command Mode
bindkey -M viins ';;' vi-cmd-mode
bindkey -M viins 'jj' vi-cmd-mode
# Bind Ctrl-K/Ctrl-J to go Up/Down in History
bindkey '^K' history-substring-search-up
bindkey '^J' history-substring-search-down
##### Fix for special keys (home, end, delete, etc.)
## 2017/2/28 TODO: See if this is still necessary - if it is, figure out
## exactly what it's doing...
# create a zkbd compatible hash;
# to add other keys to this hash, see: man 5 terminfo
typeset -A key
key[Home]=${terminfo[khome]}
key[End]=${terminfo[kend]}
key[Insert]=${terminfo[kich1]}
key[Delete]=${terminfo[kdch1]}
key[Left]=${terminfo[kcub1]}
key[Right]=${terminfo[kcuf1]}
key[PageUp]=${terminfo[kpp]}
key[PageDown]=${terminfo[knp]}
# setup key accordingly
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-buffer-or-history
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-buffer-or-history
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init () {
printf '%s' "${terminfo[smkx]}"
}
function zle-line-finish () {
printf '%s' "${terminfo[rmkx]}"
}
zle -N zle-line-init
zle -N zle-line-finish
fi
#####
# Run a local config if it exists
if [[ -f ~/.zshrc.local ]]; then
source ~/.zshrc.local
fi