-
Notifications
You must be signed in to change notification settings - Fork 3
/
.zshrc
760 lines (617 loc) · 24.3 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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
# Benchmarking {{{
# Uncomment to enable
# zmodload zsh/zprof
# }}}
# Reminders {{{
# Navigation Summary:
#
# cd <ctrl>-t means "change to directory resulting from ...
# search from HOME directory using fd and fzf"
#
# cd **; <tab> means "change to directory resulting from ...
# search from CURRENT directory using only fzf"
#
# <alt>-c means "change to directory resulting from ...
# search from CURRENT directory with fzf"
#
# cd ,paper <ctrl>-b means "change to directory resulting from ...
# search through recent directories with fzf and fasd"
#
# }}}
# External Plugins {{{
# ﰌ gkapfham ~/.zsh exa --long --header --git --classify --all
# Permissions Size User Date Modified Name
# drwxrwxr-x - gkapfham 8 Mar 20:20 fast-syntax-highlighting/
# drwxrwxr-x - gkapfham 8 Mar 20:20 fzf-tab/
# drwxrwxr-x - gkapfham 8 Mar 20:20 gitstatus/
# drwxrwxr-x - gkapfham 8 Mar 20:20 zsh-autosuggestions/
# drwxrwxr-x - gkapfham 8 Mar 20:20 zsh-git-prompt/
# drwxrwxr-x - gkapfham 8 Mar 20:20 zsh-syntax-highlighting/
# NOTES:
# -- forked zsh-git-prompt is heavily modified
# -- forked gitstatus is heavily modified
# -- zsh-git-prompt is deprecated for gitstatus
# -- both fast-syntax-highlighting and zsh-syntax-highlighting
# are currently available, but the former is in current use
# Exports {{{
# Define the shell to always be zsh
export SHELL="/usr/sbin/zsh"
# Redefine the LS_COLORS so that:
# --> directories are not displayed as bold
export LS_COLORS="rs=0:di=0;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:"
# Define the EXA_COLORS so that:
# --> user name is not displayed as bold
# --> group name is not displayed as bold
# --> read bit for user is not displayed as bold
# --> write bit for user is not displayed as bold
export EXA_COLORS="uu=0;33:gu=0;33:ur=0;33:uw=0;31"
# 256 color mode with bold and italics
# NOTE: Use of tmux-256color does not
# correctly set the title of terminal
export TERM="xterm-256color"
# indicate support for 24-bit true-color
# which is supported by neovim and pastel
export COLORTERM='truecolor'
# Character encoding
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"
# NeoVim as editor
export EDITOR="nvim"
# Large R history
export R_HISTSIZE="25000"
# BibTeX inputs
export BIBINPUTS=.
# Shell title
export DISABLE_AUTO_TITLE=true
# Set the browser to Firefox
export BROWSER=/usr/bin/firefox
# Path
# Strategy: place user-local binaries before system ones
# Includes setup for:
# --> Contained Python with pipx
# --> Fuzzy finding with fzf
# --> Local binaries
# --> JavaScript npm
# --> Rust with cargo
# --> Go with .gocode
# --> Poetry with .poetry
export PATH="$HOME/.local/pipx/bin:$HOME/.fzf/bin:$HOME/.local/bin:$HOME/bin:$HOME/.npm-global/bin::$HOME/.cargo/bin:$HOME/.gocode/bin:$HOME/.poetry/bin:/usr/bin/vendor_perl/:/usr/lib/lightdm/lightdm:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"
# Add the bin directory for Ruby gems to the Path
export PATH="$PATH:$(ruby -e 'puts Gem.user_dir')/bin"
# Local pyenv home
export PYENV_ROOT="$HOME/.pyenv"
# Local Gem home
export GEM_HOME=$HOME/.gem
# No warning messages in Ruby
export RUBYOPT='-W0'
# Local Go program home
export GOPATH=$HOME/.gocode
# No Java tools
unset JAVA_TOOL_OPTIONS
# No color formatting with pre-commit
export PRE_COMMIT_COLOR='never'
# Get correct spacing in python virtualenv_prompt_info
export ZSH_THEME_VIRTUALENV_SUFFIX="] "
# Define a marker to display of a "partial line"
# Normally shown as a "%"
# May appear when using Tmuxinator to start tmux
export PROMPT_EOL_MARK=' '
# Define the TERMINAL variable for i3 window manager,
# which consults this for running the i3-sensible-terminal
export TERMINAL='alacritty'
# Define the pager used for manual pages to be Neovim,
# making it possible to then use "gO" to populate and load the
# location list and then navigate the sections in the man page.
# Note that after population of the location list it is possible
# to view sections again by using <Leader>c instead of "gO".
export MANPAGER='nvim +Man!'
# Configure bat to use a matching theme
export BAT_THEME='Vitamin-Onec'
# Configure less to use lesspipe.sh so that it is possible
# to perform conversion of files to plaintext. For instance,
# using "less file.pdf" will now file.pdf's text in the terminal
export LESSOPEN="|lesspipe.sh %s"
# Configure pipx to install itself and other managed
# Python programs to a directory only for pipx. Note
# that this ensures that pipx and other programs are
# not installed to ~./local/bin/ which is a directory
# that the Makefile in this repository overwrites
export PIPX_BIN_DIR="$HOME/.local/pipx/bin"
# Set the home for the pipx program, using the default
# value that would be used without setting here. Note
# that setting this variable makes the default explicit.
export PIPX_HOME="$HOME/.local/pipx"
# }}}
# System Aliases {{{
# MuPDF resolution
alias mupdf="mupdf -r 288"
# Htop
alias htop="htop -C"
# IPython
alias ipython="ipython --TerminalInteractiveShell.editing_mode=vi"
# More and cat are aliased to bat
alias more="bat"
alias cat="bat"
# Directory listing with a simple command
alias ka="exa --group-directories-first --grid --long --sort=name"
# Use the exa command to display a tree,
# ensuring better color scheme
alias tree="exa --tree --level=2 --long"
# Always run pacman as root
alias pacman="sudo pacman"
# Alias to search for packages in yay (which includes non-AUR)
# and 1) then display details about the package in an fzf preview and
# 2) display the details about the package in shell after selection
alias yaysearch="yay -Slq | fzf --multi --preview 'yay -Si {1}' | xargs -ro yay -Si"
# }}}
# Git Aliases {{{
# Markdown pull request with hub
alias hubmdpr="hub -c core.commentChar='%' pull-request"
# Markdown issue with hub
alias hubmdis="hub -c core.commentChar='%' issue create"
# Reusable format strings for git aliases
GIT_PRETTY_FORMAT_AUTHOR="--pretty=\"%C(bold green)%h%Creset %C(yellow)%an%Creset%C(auto)%d%Creset %s\""
# Display colorize git output in blocks
alias gls="git slog"
# Display a colorized git log with authors in a graph
alias gla="git log --graph $GIT_PRETTY_FORMAT_AUTHOR"
# Display a colorized git log with all references and authors
alias glaa='gla --all'
# Define functions and an alias for switching between git branches
# https://polothy.github.io/post/2019-08-19-fzf-git-checkout/
fzf-git-branch() {
git rev-parse HEAD > /dev/null 2>&1 || return
git branch --color=always --all --sort=-committerdate |
grep -v HEAD |
fzf --height 75% --ansi --no-multi --preview-window right:65% \
--preview 'git log -n 50 --color=always --date=short --pretty="format:%C(auto)%cd %h%d %s" $(sed "s/.* //" <<< {})' |
sed "s/.* //"
}
# Run git checkout and call the previous function
# for display details about the branch
fzf-git-checkout() {
git rev-parse HEAD > /dev/null 2>&1 || return
local branch
branch=$(fzf-git-branch)
if [[ "$branch" = "" ]]; then
echo "No branch selected."
return
fi
# If branch name starts with 'remotes/' then it is a remote branch. By
# using --track and a remote branch name, it is the same as:
# git checkout -b branchname --track origin/branchname
if [[ "$branch" = 'remotes/'* ]]; then
git checkout --track $branch
else
git checkout $branch;
fi
}
# Define an alias that uses fzf to select git branches
alias gcob='fzf-git-checkout'
# }}}
# Oh-My-Zsh and Zsh Plugins/Scripts {{{
# Save startup time by disabling
DISABLE_UPDATE_PROMPT=true
DISABLE_AUTO_UPDATE=true
# Configuration path
ZSH=$HOME/.oh-my-zsh
# Default theme
ZSH_THEME="vitamin-onec"
# Timestamps
HIST_STAMPS="mm/dd/yyyy"
# NOTE: use this plugin as a backup in case alternate is unavailable
# Plugin: zsh-syntax-highlighting
# source $HOME/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# Plugin: fast-syntax-highlighting
source $HOME/.zsh/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
# Plugin: zsh-vi-mode
source $HOME/.zsh/zsh-vi-mode/zsh-vi-mode.plugin.zsh
# Plugin: Request all plugins from oh-my-zsh
#
# NOTE: these are all loaded in the .oh-my-zsh.sh script
# and some of these could be loaded through zsh-defer.
#
# However, not all of them work with zsh-defer and some
# benchmarking suggests that there is not any/much improvement
# in performance. As such, they are all being included here!
plugins=(git git-extras shrink-path tmux tmuxinator virtualenv)
# Reload all of the completion modules before
# sourcing the specialized Oh-My-Zsh script
# NOTE: this is needed to avoid errors
# shell startup and after typing each command
autoload -Uz compinit && compinit
# Load customized oh-my-zsh script
source $HOME/.oh-my-zsh.sh
# Plugin: Fast, git-stacular prompt with gitstatus
# Note: local modifications to this plugin
source $HOME/.zsh/gitstatus/gitstatus.prompt.zsh
# Plugin: fzf-tab
# Note: must be sourced after all other plugins to ensure
# that tab-completion binds to it and not to oh-my-zsh method
source $HOME/.zsh/fzf-tab/fzf-tab.plugin.zsh
# Disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# Set descriptions format to enable group support
zstyle ':completion:*:descriptions' format '[%d]'
# Set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# Preview directory's content with exa when completing cd,
# thereby showing a preview window with Fzf to the right
# of the cd command that shows the contents of current directory
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath'
# Switch group using `,` and `.` (note that different
# groups might include different types of branches when
# tab completing a git checkout command)
zstyle ':fzf-tab:*' switch-group ',' '.'
# Set the default color to be the color 245 out of
# the 256 colors available in the terminal window the color 245 out of
# the 256 colors available in the terminal window
zstyle ':fzf-tab:*' default-color $'\033[38;5;245m'
# Set that when groups are available (i.e., there are different
# types of completions that are possible) the names of the
# groups should be visible at the top of the Fzf-Tab menu
zstyle ':fzf-tab:*' show-group full
# Do not show a symbol to the left of a file or a directory
zstyle ':fzf-tab:*' prefix ''
# Pass commands to the Fzf program that defines the colors. These
# colors are the same as those used to configure Fzf when it runs
# otherwise in the terminal window or in a text editor like Vim or Neovim
zstyle ":fzf-tab:*" fzf-flags --color='fg:#8a8a8a,bg:#1c1c1c,hl:#5f8700' --color='fg+:#afaf5f,bg+:#1c1c1c,hl+:#d78700' --color='info:#87afd7,prompt:#87afd7,pointer:#d78700' --color='marker:#d78700,spinner:#875f87,header:#875f87'
# Plugin: zsh-autosuggestions
source $HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
# Set a light grey color as the foreground color for the suggestion
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=240'
# Disable autosuggestions for buffers longer than the specified length
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
# Perform autosuggestions in an async fashion
ZSH_AUTOSUGGEST_USE_ASYNC=1
# First type to find a suggestion from the history and, if
# a match is not found, suggest one from the zsh completion engine
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
# Use CTRL-<Space> to accept a specific auto suggestion
bindkey '^ ' autosuggest-accept
# }}}
# FASD {{{
# create the FASD cache so that the terminal loads quickly
# but I still get all of the FASD features
fasd_cache="$HOME/.fasd-init-zsh"
if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install >| "$fasd_cache"
fi
source "$fasd_cache"
unset fasd_cache
# Use FZF to filter the output of FASD anywhere it is a command
autoload -U modify-current-argument
fzf-fasd-widget() {
# divide the commands buffer into words
local words i beginword start
i=0
start=1
beginword=0
words=("${(z)BUFFER}")
while (( beginword <= CURSOR )); do
(( i++ ))
(( beginword += ${#words[$i]}+1 ))
done
# extract the first and current words
# extract the first letter as a potential trigger
FIRSTWORD="$words[$start]"
CURRENTWORD="$words[$i]"
TRIGGERLETTER=${CURRENTWORD:0:1}
# the trigger of "," was used, so start
# the use of FASD and FZF with this word
if [ "$TRIGGERLETTER" = "," ]; then
unset 'words[${#words[@]}]'
PASTWORDS=${words[@]}
CURRENTWORD="${CURRENTWORD:1:${#CURRENTWORD}}"
LBUFFER="${PASTWORDS}$(fasd -d -l -r $CURRENTWORD | \
fzf --query="$CURRENTWORD" --select-1 --exit-0 --height=25% --reverse --tac --no-sort --cycle)"
# the trigger of "," was not used, so
# search interactively based on user input
else
PASTWORDS=${words[@]}
CURRENTWORD=""
LBUFFER="${PASTWORDS} $(fasd -d -l -r $CURRENTWORD | \
fzf --query="$CURRENTWORD" --select-1 --exit-0 --height=25% --reverse --tac --no-sort --cycle)"
fi
# update the prompt with the result of using FASD and FZF
local ret=$?
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
# Create a binding so that you can type "cd ,pract^B"
# (as an example) to trigger this integrated widget
zle -N fzf-fasd-widget
bindkey '^B' fzf-fasd-widget
# }}}
# FZF {{{
# Setup fzf, its auto-completions, and key bindings
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Match the vim-vitamin-onec colorscheme
# Color scheme: https://github.com/gkapfham/vim-vitamin-onec
# 256 Color reference: https://jonasjacek.github.io/colors/
export FZF_DEFAULT_OPTS='
--no-bold
--cycle
--bind ctrl-f:page-down,ctrl-b:page-up
--color=fg:#8a8a8a,bg:#1c1c1c,hl:#5f8700
--color=fg+:#afaf5f,bg+:#1c1c1c,hl+:#d78700
--color=info:#87afd7,prompt:#87afd7,pointer:#d78700
--color=marker:#d78700,spinner:#875f87,header:#875f87'
# Same colorscheme but in 256 colors,
# note that this does not use the HTML color
# codes and instead uses those available at:
# https://jonasjacek.github.io/colors/
# export FZF_DEFAULT_OPTS='
# --no-bold
# --cycle
# --bind ctrl-f:page-down,ctrl-b:page-up
# --color=fg:243,bg:234,hl:64
# --color=fg+:143,bg+:234,hl+:172
# --color=info:110,prompt:110,pointer:172
# --color=marker:172,spinner:96,header:96'
# Trigger fzf completion using the semi-colon key instead of **
export FZF_COMPLETION_TRIGGER=';'
# Configure fzf to work with fast-finder called fd
export FZF_DEFAULT_COMMAND="fd . $HOME"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
# }}}
# Zsh-Vi-Mode {{{
# Run all of the code in this function after
# initializing the zsh-vi-mode plugin. Note that
# many of these steps are needed because of the
# fact that the zsh-vi-mode plugin overwrites
# keybindings, making it necessary to run again
function zvm_after_init() {
# Re-source the use of fzf in zsh after starting zsh-vi-mode
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Re-Source and configure the zsh-auto-suggestions plugin
source $HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=240'
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
ZSH_AUTOSUGGEST_USE_ASYNC=1
bindkey '^ ' autosuggest-accept
# Use FZF to filter the output of FASD anywhere it is a command
autoload -U modify-current-argument
fzf-fasd-widget() {
# divide the commands buffer into words
local words i beginword start
i=0
start=1
beginword=0
words=("${(z)BUFFER}")
while (( beginword <= CURSOR )); do
(( i++ ))
(( beginword += ${#words[$i]}+1 ))
done
# extract the first and current words
# extract the first letter as a potential trigger
FIRSTWORD="$words[$start]"
CURRENTWORD="$words[$i]"
TRIGGERLETTER=${CURRENTWORD:0:1}
# the trigger of "," was used, so start
# the use of FASD and FZF with this word
if [ "$TRIGGERLETTER" = "," ]; then
unset 'words[${#words[@]}]'
PASTWORDS=${words[@]}
CURRENTWORD="${CURRENTWORD:1:${#CURRENTWORD}}"
LBUFFER="${PASTWORDS}$(fasd -d -l -r $CURRENTWORD | \
fzf --query="$CURRENTWORD" --select-1 --exit-0 --height=25% --reverse --tac --no-sort --cycle)"
# the trigger of "," was not used, so
# search interactively based on user input
else
PASTWORDS=${words[@]}
CURRENTWORD=""
LBUFFER="${PASTWORDS} $(fasd -d -l -r $CURRENTWORD | \
fzf --query="$CURRENTWORD" --select-1 --exit-0 --height=25% --reverse --tac --no-sort --cycle)"
fi
# update the prompt with the result of using FASD and FZF
local ret=$?
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
# Create a binding so that you can type "cd ,pract^B"
# (as an example) to trigger this integrated widget
zle -N fzf-fasd-widget
bindkey '^B' fzf-fasd-widget
# Use FZF to filter the output of FASD anywhere it is a command
autoload -U modify-current-argument
fzf-fasd-widget() {
# divide the commands buffer into words
local words i beginword start
i=0
start=1
beginword=0
words=("${(z)BUFFER}")
while (( beginword <= CURSOR )); do
(( i++ ))
(( beginword += ${#words[$i]}+1 ))
done
# extract the first and current words
# extract the first letter as a potential trigger
FIRSTWORD="$words[$start]"
CURRENTWORD="$words[$i]"
TRIGGERLETTER=${CURRENTWORD:0:1}
# the trigger of "," was used, so start
# the use of FASD and FZF with this word
if [ "$TRIGGERLETTER" = "," ]; then
unset 'words[${#words[@]}]'
PASTWORDS=${words[@]}
CURRENTWORD="${CURRENTWORD:1:${#CURRENTWORD}}"
LBUFFER="${PASTWORDS}$(fasd -d -l -r $CURRENTWORD | \
fzf --query="$CURRENTWORD" --select-1 --exit-0 --height=25% --reverse --tac --no-sort --cycle)"
# the trigger of "," was not used, so
# search interactively based on user input
else
PASTWORDS=${words[@]}
CURRENTWORD=""
LBUFFER="${PASTWORDS} $(fasd -d -l -r $CURRENTWORD | \
fzf --query="$CURRENTWORD" --select-1 --exit-0 --height=25% --reverse --tac --no-sort --cycle)"
fi
# update the prompt with the result of using FASD and FZF
local ret=$?
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
# Create a binding so that you can type "cd ,pract^B"
# (as an example) to trigger this integrated widget
zle -N fzf-fasd-widget
bindkey '^B' fzf-fasd-widget
}
# Configure the shell so that it uses jk for escape
# --> when currently in insert mode
ZVM_VI_INSERT_ESCAPE_BINDKEY="jk"
# --> when currently in visual mode
ZVM_VI_VISUAL_ESCAPE_BINDKEY="jk"
# Customize the background color of highlights in
# the terminal window when in visual mode. Note that
# you cannot change the foreground color so it is
# important to pick a background color that is suitable
# for the standard text colors used in the terminal
ZVM_VI_HIGHLIGHT_BACKGROUND="#303030"
# Define a slightly faster timeout delay for key
# pressed in the zsh-vi-mode plugin
ZVM_KEYTIMEOUT=0.2
# Disable the cursor mode because using terminals
# and Neovim in tmux will cause this value to
# change depending on the mode for Neovim
ZVM_CURSOR_STYLE_ENABLED=false
# Run this function every time that the
# zsh-vi-mode plugin detects that the
# mode changes, ultimately giving the
# opportunity to define the right-side
# prompt to give an indicator of the mode
function zvm_after_select_vi_mode() {
case $ZVM_MODE in
$ZVM_MODE_NORMAL)
RPROMPT="%{$fg_bold[red]%}%{$reset_color%}"
zle reset-prompt
;;
$ZVM_MODE_INSERT)
RPROMPT=""
zle reset-prompt
;;
$ZVM_MODE_VISUAL)
RPROMPT="%{$fg_bold[red]%}%{$reset_color%}"
zle reset-prompt
;;
$ZVM_MODE_VISUAL_LINE)
RPROMPT="%{$fg_bold[red]%}%{$reset_color%}"
zle reset-prompt
;;
$ZVM_MODE_REPLACE)
RPROMPT="%{$fg_bold[red]%}%{$reset_color%}"
zle reset-prompt
;;
esac
}
# }}}
# Tmux {{{
# Display all of the open tmux sessions with fzf
tms() {
local session
newsession=${1:-Work}
session=$(tmux list-sessions -F "#{session_name}" | \
fzf --query="$1" --select-1 --exit-0 --cycle) &&
tmux attach-session -t "$session" || tmux new-session -s $newsession
}
# Display all of the possible tmuxinators with fzf
tmm() {
# NOTE: Use the /usr/sbin/ls command since "ls" is now aliased to use "exa" command
session=$( /usr/sbin/ls -alg ~/.tmuxinator | awk '{print $8}' | cut -d'.' -f1 | sed 1,2d | \
fzf --query="$1" --select-1 --exit-0 --cycle) &&
tmuxinator "$session"
}
# Define the name of a tmux pane, display in the status-right
function workspace {
readonly name=${1:?"Specify the name of the workspace."}
tmux select-pane -T $name
}
# }}}
# Pyenv {{{
# Fast load of pyenv immediately upon shell startup
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(command pyenv init - zsh --no-rehash)"
# }}}
# Nvm {{{
# Lazy load nvm to avoid slow shell startup times
# Note that this requires you to type one of these
# commands before they will initially work
if [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
alias nvm='unalias nvm node npm && . "$NVM_DIR"/nvm.sh && nvm'
alias node='unalias nvm node npm && . "$NVM_DIR"/nvm.sh && node'
alias npm='unalias nvm node npm && . "$NVM_DIR"/nvm.sh && npm'
fi
# }}}
# Pipenv {{{
# Ensure that Pipenv can find the version of Python
# that is managed by the Pyenv tool
export PIPENV_PYTHON="$HOME/.pyenv/shims/python"
# }}}
# Perl {{{
# Ensure that the user-install version of cpanm is
# available to neovim, enabling health checks to pass
if (command -v perl && command -v cpanm) >/dev/null 2>&1; then
test -d "$HOME/perl5/lib/perl5" && eval $(perl -I "$HOME/perl5/lib/perl5" -Mlocal::lib)
fi
# }}}
# User Commands {{{
# Display disk usage in a friendly manner
usage() {
du -h --max-depth="${2:-1}"\
"${1:-.}" |\
sort -h |\
sed "s:\./::" |\
sed "s:$HOME:~:"
}
# Run a benchmark for zsh startup time
benchmark() {
for i in $(seq 1 10); do /usr/bin/time zsh -i -c exit; done
}
# Store the ssh passphrase for easy git use
secure() {
/usr/bin/ssh-add -t 432000
}
# Always display directory contents after a change of directory
function chpwd() {
emulate -L zsh
exa --group-directories-first --grid --long --sort=name
}
# }}}
# Color Commands {{{
# Print the 256 color palette
# Online version available at:
# https://jonasjacek.github.io/colors/
palette() {
local -a colors
for i in {000..255}; do
colors+=("%F{$i}$i%f")
done
print -cP $colors
}
# Print the zsh color code for a 256 color number.
# This command is useful because it yields the
# color code used with Fzf-Tab and with LS_COLORS.
printcolor() {
local color="%F{$1}"
echo -E ${(qqqq)${(%)color}}
}
# }}}
# Redefine Aliases {{{
# Already defined in oh-my-zsh, redefine to use exa
alias ls="exa --color=always"
# }}}
if [ -n "${NVIM_LISTEN_ADDRESS+x}" ]; then
export COLORTERM="truecolor"
fi
# Benchmarking {{{
# Uncomment to enable
# zprof
# }}}