-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdot_zshrc
More file actions
300 lines (263 loc) · 9.68 KB
/
Copy pathdot_zshrc
File metadata and controls
300 lines (263 loc) · 9.68 KB
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
source $HOME/.commonfuncs
# Package manager {{{1
# -----------------------------------------------------------------
# Set up zinit
typeset -A ZINIT
ZINIT[HOME_DIR]="${HOME}/.local/share/zinit"
source "${ZINIT[HOME_DIR]}/zinit.git/zinit.zsh"
# zinit completions
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# Aliases {{{1
# -----------------------------------------------------------------
# set up dir hashes
hash -d L=/var/log
hash -d P=$HOME/work/projects
hash -d PP=$HOME/work/presentation
hash -d D=$HOME/Documents
[ -d "$HOME/Sites" ] && hash -d S=$HOME/Sites
[ -d /data ] && hash -d Z=/data
# set up common aliases between shells (stuff like rbenv, nvm, pyenv, asdf etc.)
source $HOME/.commonrc
## global aliases
# disable the plonesite part in a buildout run, example: $ bin/buildout -N psef
alias -g psef="plonesite:enabled=false"
# replace the plonesite in a buildout run, example: $ bin/buildout -N pssr
alias -g pssr="plonesite:site-replace=true"
# easily get to the site packages dir of any python install, example: $ cd $(python2.5 site-packages)
alias -g site-packages='-c "from distutils.sysconfig import get_python_lib; print get_python_lib()"'
# some pipes
if [ $(uname) = "Darwin" ]; then
alias -g S='| sed -Ee'
alias -g SP='| sed -n -Ee'
else
alias -g S='| sed -re'
alias -g SP='| sed -n -re'
fi
alias -g A='| awk'
alias -g G='| grep -Ei'
alias -g C='| cut'
alias -g CF='| cut -d" " -f'
alias -g L='| less'
alias -g M='| more'
alias -g H='| head'
alias -g T='| tail'
alias -g W='| wc'
alias -g WL='| wc -l'
alias -g JQ='| jq -r'
# copying
if checkPath clipboard; then
alias -g CP='| clipboard'
elif checkPath pbcopy; then
alias -g CP='| pbcopy'
elif checkPath xclip; then
alias -g CP='| xclip -i -selection clipboard'
elif checkPath xsel; then
alias -g CP='| xsel -ib'
fi
# Diffing
if checkPath colordiff; then
alias -g CD='| colordiff'
else
alias -g CD='| vim -R "+syntax on" -'
fi
alias -g pretty_json="| python -mjson.tool | vim -R +'set ft=javascript' -"
# moreutils
alias -g VI='| vipe'
alias -g TS='| ts -i'
# fuzzy finder
alias -g FZ='| fzf -m'
alias -g FZF='| fzf -m'
# Options {{{1
# -----------------------------------------------------------------
# automatically print timing statistics if the command took longer
# than a minute
export REPORTTIME=60
setopt NO_BEEP
# Changing Directories
setopt AUTO_CD
setopt CDABLE_VARS
setopt AUTO_PUSHD
setopt PUSHDMINUS
setopt PUSHD_IGNORE_DUPS
# Include dot files in globbing
# use the following to ignore dot files: % ^.*
setopt GLOB_DOTS
# History
setopt HIST_SAVE_NO_DUPS
setopt HIST_VERIFY
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt EXTENDED_HISTORY
alias histappend="fc -AI"
alias histread="fc -R"
# set up the history-complete-older and newer
zstyle ':completion:*:history-words' stop yes
zstyle ':completion:*:history-words' remove-all-dups yes
zstyle ':completion:*:history-words' list false
zstyle ':completion:*:history-words' menu yes
# Keybinds {{{1
# -----------------------------------------------------------------
# use vi mode
bindkey -v
# Use jj for ESC
bindkey "jj" vi-cmd-mode
bindkey "jk" vi-cmd-mode
# use home and end in addition to ^e and ^a
bindkey -M viins '^A' vi-beginning-of-line
bindkey -M viins '^E' vi-end-of-line
bindkey -M viins '^[[H' vi-beginning-of-line
bindkey -M viins '^[[F' vi-end-of-line
# use delete as forward delete
bindkey -M viins '\e[3~' vi-delete-char
# line buffer
bindkey -M viins '^B' push-line-or-edit
# change the '-' for up in history, always kills my command editing.
bindkey -M vicmd '^[OA' vi-up-line-or-history
# Make sure that shift-tab doesn't take me out of insert mode. going to the
# end of the line will work 99% of the time.
bindkey -M viins '^[[Z' vi-end-of-line
# change the shortcut for expand alias
bindkey -M viins '^X' _expand_alias
# Search backwards with a pattern
bindkey -M vicmd '^R' history-incremental-pattern-search-backward
bindkey -M vicmd '^F' history-incremental-pattern-search-forward
# set up for insert mode too
bindkey -M viins '^R' history-incremental-pattern-search-backward
bindkey -M viins '^F' history-incremental-pattern-search-forward
# whole line completion with zsh-users/zsh-history-substring-search plugin
bindkey -M viins "^[OA" history-substring-search-up
bindkey -M viins "^[[A" history-substring-search-up
bindkey -M vicmd "k" history-substring-search-up
bindkey -M vicmd "j" history-substring-search-up
bindkey -M viins "^[OB" history-substring-search-down
bindkey -M viins "^[[B" history-substring-search-down
bindkey -M viins "^N" up-line-or-search
bindkey -M viins "^P" down-line-or-search
# edit current command in $EDITOR
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# History {{{1
# -----------------------------------------------------------------
# set up history
HISTSIZE=50000
SAVEHIST=50000
HISTFILE=~/.zsh_history
export HISTFILE HISTSIZE SAVEHIST
# Append history after 30 minutes of inactivity
export TMOUT=900
function TRAPALRM() { histappend }
# Completions {{{1
# -----------------------------------------------------------------
autoload -Uz compinit
for dump in ~/.zcompdump(N.mh+24); do
compinit
done
compinit -C
# custom completions
if [ -d '/usr/share/games/fortunes' ]; then
compctl -s '$(\ls /usr/share/games/fortunes | grep .dat | sed "s/.dat//")' fortune makeMeLaugh lulz
fi
# make sure git-achievements can complete like git
compdef git-achievements=git
## case-insensitive (all),partial-word and then substring completion
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# Prompt {{{1
# -----------------------------------------------------------------
# Use starship prompt if it's available
if checkPath starship; then
eval "$(starship init zsh)"
function precmd {
# make sure that all new commands are available
rehash
}
else
if checkPath git and checkPath python; then
# Make git status information available
export ZSH_THEME_GIT_PROMPT_NOCACHE="True"
source ~/.zsh/git-prompt/gitstatus.sh
else
alias git_super_status='echo'
fi
# use some crazy ass shell prompt
# thanks to for the basis: http://aperiodic.net/phil/prompt/
ME="clayton"
source ~/.zshprompt
fi
# Plugin config {{{1
# -----------------------------------------------------------------
# load all the zi plugins here (after compinit, so completion-dependent
# plugins load correctly, and after the manual bindkey/zle -N setup above so
# syntax-highlighting wraps those widgets)
source $HOME/.zsh_plugins
# Highlighting {{{2
# -----------------------------------------------------------------
# Set up zsh highlighters
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets cursor root)
# set up command line syntax highlighting overrides
ZSH_HIGHLIGHT_STYLES[builtin]='fg=green,bold'
ZSH_HIGHLIGHT_STYLES[function]='fg=green,underline'
ZSH_HIGHLIGHT_STYLES[alias]='fg=255,bg=green'
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=yellow'
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=yellow'
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]='fg=yellow,underline'
ZSH_HIGHLIGHT_STYLES[globbing]='fg=255,bold,bg=blue'
ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=black,bold,bg=blue'
# FZF {{{2
# -----------------------------------------------------------------
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# teamocil {{{2
# -----------------------------------------------------------------
if [ -d "$HOME/.teamocil" ]; then
compctl -g '~/.teamocil/*(:t:r)' teamocil
fi
# Worktrunk {{{2
# -----------------------------------------------------------------
if command -v wt >/dev/null 2>&1; then
eval "$(command wt config shell init zsh)"
fi
# Atuin {{{2
# -----------------------------------------------------------------
# NOTE: doing this after fzf to override ctrl+r history
if checkPath atuin; then
eval "$(atuin init zsh --disable-up-arrow)"
fi
# Auto suggestions {{{2
# -----------------------------------------------------------------
# commands that should never be auto-suggested, built up and joined with |
typeset -a _git_ignore=(
"add *"
"ci *"
"commit -m *"
"cob *"
"checkout -b *"
)
typeset -a _autosuggest_ignore=(
"(g|git) (${(j:|:)_git_ignore})"
"(ls|lsa) *"
"(cp|mv|rm) *"
"beet import *"
)
ZSH_AUTOSUGGEST_HISTORY_IGNORE="(${(j:|:)_autosuggest_ignore})"
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
# Advanced shell history
if checkPath atuin; then
# atuin's autosuggest strategy queries its own DB and ignores
# ZSH_AUTOSUGGEST_HISTORY_IGNORE. Wrap it so suggestions (but not
# recorded history) honor the ignore pattern: pull a few candidates
# and return the first that doesn't match.
_zsh_autosuggest_strategy_atuin() {
emulate -L zsh
setopt EXTENDED_GLOB
local line
suggestion=""
while IFS= read -r line; do
if [[ -z $ZSH_AUTOSUGGEST_HISTORY_IGNORE || $line != ${~ZSH_AUTOSUGGEST_HISTORY_IGNORE} ]]; then
suggestion="$line"
break
fi
done < <(ATUIN_QUERY="$1" atuin search --cmd-only --exit 0 --filter-mode directory --limit 10 --search-mode prefix --reverse 2>/dev/null)
}
fi
# vim: fdm=marker ts=2 sts=2 sw=2 et