-
Notifications
You must be signed in to change notification settings - Fork 1
/
zshrc
256 lines (212 loc) · 8.75 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
#####################
# PATH #
#####################
path=("$HOME/.dotfiles/bin" /usr/local/sbin /usr/local/bin "$path[@]")
[ -f ~/.exports.local ] && source ~/.exports.local
#Only load homebrew paths when installed in default location
if [ -f "/opt/homebrew/bin/brew" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"
fi
#####################
# ENV VARIABLE #
#####################
export EDITOR='vim'
export VISUAL=$EDITOR
export PAGER='less'
export SHELL=`which zsh`
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
export BAT_THEME="Solarized (dark)"
export HOMEBREW_NO_ANALYTICS=1
export ENHANCD_FILTER=fzf:fzy:peco
export ERL_AFLAGS="-kernel shell_history enabled"
export OPERATING_SYSTEM=$(uname | tr '[:upper:]' '[:lower:]')
export TERM=xterm-256color
GREP_OPTIONS="--color=auto"
#####################
# ZINIT #
#####################
#Load ziint base
source "$HOME/.dotfiles/zsh/zinit/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
#####################
# THEME #
#####################
POWERLEVEL10K_MODE='nerdfont-complete'
DEFAULT_USER=`whoami`
zinit light-mode for \
depth=1 @romkatv/powerlevel10k \
is-snippet ~/.dotfiles/zsh/p10k.zsh
#####################
# ZINIT ANNEXES #
#####################
zinit light-mode for \
@zdharma-continuum/zinit-annex-bin-gem-node \
@zdharma-continuum/zinit-annex-rust \
@zdharma-continuum/zinit-annex-readurl \
@zdharma-continuum/zinit-annex-patch-dl
#####################
# ZINIT PLUGINS #
#####################
#https://github.com/zdharma-continuum/fast-syntax-highlighting/issues/205 - Git disabled on zdharma-continuum/fast-syntax-highlighting
zinit light-mode wait lucid for \
@b4b4r07/enhancd \
@ael-code/zsh-colored-man-pages \
@hlissner/zsh-autopair \
@le0me55i/zsh-extract \
@jreese/zsh-titles \
@xPMo/zsh-toggle-command-prefix \
@wfxr/forgit \
OMZ::lib/clipboard.zsh \
OMZ::lib/directories.zsh \
@zpm-zsh/ls \
is-snippet ~/.dotfiles/zsh/ctrl-z-fzf.plugin.zsh \
multisrc:'shell/*.zsh' @junegunn/fzf \
atload='_set_fzf_history' @Aloxaf/fzf-tab \
atload"!_zsh_autosuggest_start" zsh-users/zsh-autosuggestions \
blockf zsh-users/zsh-completions atload"_history_substring_bind_keys" @zsh-users/zsh-history-substring-search \
atinit" zpcompinit; zpcdreplay" atload"FAST_HIGHLIGHT[chroma-git]=0" zdharma-continuum/fast-syntax-highlighting
#####################
# ZINIT PROGRAMS #
#####################
#Some of these are not available on servers, this creates availability
zinit wait silent light-mode as:program for \
from:gh-r pick"bin/exa" ogham/exa \
from:gh-r mv:'bat-**/bat -> bat' @sharkdp/bat \
from:gh-r mv"fd* -> fd" sbin"fd/fd" @sharkdp/fd \
pick"bin/git-dsf" zdharma-continuum/zsh-diff-so-fancy
# make @mbrubeck/compleat
# from:gh-r mv:"direnv* -> direnv" atclone'./direnv hook zsh > zhook.zsh' atpull'%atclone' pick"direnv" src="zhook.zsh" @direnv/direnv
# from:gh-r @junegunn/fzf-bin \
#####################
# COMPLETIONS #
#####################
zinit wait lucid as'completion' light-mode blockf for \
has'exa' https://github.com/ogham/exa/blob/master/completions/zsh/_exa \
has'fd' https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/fd/_fd
local extract="
# trim input
local in=\${\${\"\$(<{f})\"%\$'\0'*}#*\$'\0'}
# get ctxt for current completion
local -A ctxt=(\"\${(@ps:\2:)CTXT}\")
# real path
local realpath=\${ctxt[IPREFIX]}\${ctxt[hpre]}\$in
realpath=\${(Qe)~realpath}
"
zstyle ':completion:*' completer _expand _complete _ignored _approximate
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*' menu select=2
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*:descriptions' format '-- %d --'
zstyle ':completion:*:processes' command 'ps -au$USER'
zstyle ':completion:complete:*:options' sort false
zstyle ':fzf-tab:complete:_zlua:*' query-string input
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm,cmd -w -w"
zstyle ':fzf-tab:complete:kill:argument-rest' extra-opts --preview=$extract'ps --pid=$in[(w)1] -o cmd --no-headers -w -w' --preview-window=down:3:wrap
zstyle ':fzf-tab:complete:*:*' extra-opts --preview=$extract'$HOME/.dotfiles/bin/preview $realpath'
#####################
# SOURCES #
#####################
#Only runs command when source file has changed
function _run_if_changed() {
hash=$(md5sum $1 | awk '{ print $1 }')
shift
mkdir -p ~/.zinit/file-cache/
disk_hash=~/.zinit/file-cache/$hash-md5sum
if [ ! -f $disk_hash ] || ! grep -q "$hash" "$disk_hash"; then
$@ && echo $hash > "$disk_hash"
fi
}
zinit light-mode wait silent is-snippet for \
atinit='_source_local' /dev/null
# Workaround to source ones that include completions
_source_local() {
autoload -Uz compinit && compinit
source ~/.dotfiles/zsh/functions.zsh
source ~/.dotfiles/zsh/aliases.zsh
[ -f ~/.aliases.local ] && source ~/.aliases.local
[ -f ~/.zshrc.local ] && source ~/.zshrc.local
_run_if_changed ~/.vimrc.bundles vim -u "$HOME"/.vimrc.bundles +PlugUpdate +PlugClean! +qall 2&> /dev/null
}
#####################
# HISTORY #
#####################
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zhistory"
HISTSIZE=290000
SAVEHIST=$HISTSIZE
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_USE_ASYNC=1
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
#ZSH_AUTOSUGGEST_MANUAL_REBIND=1
HISTORY_IGNORE='(l|ls|ll|cd|cd ..|pwd|exit|date|history)'
_set_fzf_history() {
where fzf-history-widget | sed 's/fc -rl/fc -ril/' | source /dev/stdin \
&& export FZF_CTRL_R_OPTS="--preview 'echo {1..3}; echo {4..} | bat --style=plain --language=zsh' --preview-window down:3:wrap --bind '?:toggle-preview'"
}
_history_substring_bind_keys() {
if [ "$OPERATING_SYSTEM" = "darwin" ]; then
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
elif [ "$OPERATING_SYSTEM" = "linux" ]; then
# https://superuser.com/a/1296543
# key dict is defined in /etc/zsh/zshrc
bindkey "$key[Up]" history-substring-search-up
bindkey "$key[Down]" history-substring-search-down
fi
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
}
#####################
# SETOPT #
#####################
setopt extendedglob # Enable extended globbing
setopt extended_history # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_all_dups # ignore duplicated commands history list
setopt hist_ignore_space # ignore commands that start with space
setopt hist_verify # show command with history expansion to user before running it
setopt inc_append_history # add commands to HISTFILE in order of execution
setopt share_history # share command history data
setopt always_to_end # cursor moved to the end in full completion
setopt hash_list_all # hash everything before completion
setopt completealiases # complete alisases
setopt always_to_end # when completing from the middle of a word, move the cursor to the end of the word
setopt complete_in_word # allow completion from within a word/phrase
setopt nocorrect # spelling correction for commands
setopt list_ambiguous # complete as much of a completion until it gets ambiguous.
# setopt vi #VI mode in terminal
setopt nolisttypes
setopt listpacked
setopt automenu
# awesome cd movements from zshkit
setopt autocd autopushd pushdminus pushdsilent pushdtohome cdablevars
DIRSTACKSIZE=5
#####################
# COLORING #
#####################
autoload colors && colors
export CLICOLOR=1
#####################
# FZF SETTINGS #
#####################
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules}/*" 2> /dev/null'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS='--preview="$HOME/.dotfiles/bin/preview {}" --preview-window=right:60%:wrap'
export FZF_ALT_C_OPTS='--preview="HOME/.dotfiles/bin/preview {}" --preview-window=right:60%:wrap'
export FZF_DEFAULT_OPTS=$FZF_DEFAULT_OPTS'
--reverse
--height=50%
--pointer=➜ --prompt=➜ --marker=●
--color=fg:-1,bg:-1,hl:33,fg+:235,bg+:235,hl+:33
--color=info:136,prompt:136,pointer:230,marker:230,spinner:136'
#####################
# KEY BINDINGS #
#####################
bindkey "^[[1;5D" emacs-backward-word
bindkey "^[[1;3D" emacs-backward-word
bindkey "^[[1;5C" emacs-forward-word
bindkey "^[[1;3C" emacs-forward-word
bindkey "^[[3;5~" kill-word
bindkey "^[[3;3~" kill-word