-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
294 lines (265 loc) · 10.8 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
. ~/.prep # handle boring stuff like /etc/profile and $PATH
HISTFILE=~/.histfile
HISTSIZE=99999
SAVEHIST=99999
TIMEFMT=$'\e[93m%*U/%*E cpu/real (%P), %MM mem:\e[36m %J\e[0m'
DIRSTACKSIZE=24
setopt always_to_end # move cursor to end of word during completion
setopt append_history # share history...
setopt share_history # ...across sessions
setopt auto_cd # exec a dir to cd
setopt auto_list # Automatically list choices on ambiguous completion.
setopt auto_menu # Show completion menu on a successive tab press.
setopt auto_param_slash # add a trailing slash to directory completions
setopt auto_pushd # cd acts as pushd
setopt brace_ccl # for character ranges like {a-z}
setopt chase_links # cd into link resolves link
setopt check_jobs notify # automatic job reporting
setopt complete_aliases # allow original command completion within alias
setopt complete_in_word # enable tab completion from any characters in a word
setopt extended_glob # required for various scripts in this file and otherwise
setopt hist_expire_dups_first # sharing/appending will result in dups
setopt hist_ignore_dups # don't push lines identical to the previous
setopt hist_ignore_space # don't push lines beginning with spaces
setopt hist_reduce_blanks # trim superfluous spaces
setopt hist_save_no_dups
setopt hist_verify
setopt interactive_comments # allow #-comments in interactive shells
setopt ksh_typeset # treat `local x=$(cmd)` and `local x="$(cmd)"` the same
setopt menu_complete # autoselect the first completion entry
setopt no_beep # be quiet
setopt no_match # error on bad tab-complete
setopt path_dirs # Perform path search even on command names with slashes.
setopt prompt_cr prompt_sp # prevent truncated output from ruining shell prompts
setopt rc_quotes # 'it''s okay' becomes "it's okay"
unsetopt flow_control # Disable start/stop characters in shell editor.
unsetopt bang_hist # this does nothing but cause me grief (disables !s)
function {
if [ "$SHLVL" -le 1 ] \
&& [ "${(L)HOST}" != spectre ] \
&& [ "${TERM#screen}" = "$TERM" ] \
&& [ "${TERM#tmux}" = "$TERM" ] \
&& [ -z "$ALACRITTY_LOG" ] \
&& (( $+commands[tmux] ))
then
# create a new session called "what" or attach if it already exists
local env=(LANG="en_US.UTF-8" TZ=":/etc/localtime")
local cmd=(tmux new -A -s what)
[ "${TTY#/dev/cons}" = "$TTY" ] || cmd=(script -qfec "$cmd" /dev/null)
env $env $cmd && exit
printf '\e[91m\ntmux died (%i), continuing...\n\e[0m\n' $?
fi
}
autoload -U zmv
autoload -U zrecompile
autoload -Uz zcalc
autoload edit-command-line
autoload history-search-end
zmodload zsh/mathfunc
dummy() : ### @- return 0, ignoring arguments.
dirprev() { ### @-
### rotate and change to the previous directory in the directory stack
### without consuming the prompt.
pushd -q +1
zle reset-prompt
precmd
}
dirnext() { ### @-
### rotate and change to the next directory in the directory stack
### without consuming the prompt.
pushd -q -0
zle reset-prompt
precmd
}
dirup() { ### @-
### change to the parent directory of the current working directory
### without consuming the prompt.
cd ..
zle reset-prompt
precmd
}
dirview() { ### @-
### use a fuzzy finder to select a recent directory in the directory stack
### and change to it without consuming the prompt.
local fuzzy="$(have fzy || print)"
print
if [ -n "$fuzzy" ]; then
local d="$(dirs -pl | awk '!seen[$0]++' | "$fuzzy")"
cd "$d"
else
# TODO: print under prompt if possible,
# truncate and columnize
dirs -v
fi
zle reset-prompt
precmd
}
for x (dummy dirprev dirnext dirup dirview) zle -N $x
join-lines() {
BUFFER="${BUFFER//$'\n'/ }"
CURSOR="${#BUFFER}"
}
zle -N join-lines
bindkey -e # emacs-style keybinds
# oh thank god: http://blog.samsonis.me/2013/12/bash-like-history-search-functionality-for-zsh/
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey '^[[A' history-beginning-search-backward-end # up
bindkey '^[[B' history-beginning-search-forward-end # down
bindkey '^[OA' history-beginning-search-backward-end # up
bindkey '^[OB' history-beginning-search-forward-end # down
bindkey '^[[1;5D' emacs-backward-word # ctrl+left
bindkey '^[[1;5C' emacs-forward-word # ctrl+right
bindkey '^[[1;3D' dirprev # alt+left
bindkey '^[[1;3C' dirnext # alt+right
bindkey '^[[1;3A' dirup # alt+up
bindkey '^[[1;3B' dirview # alt+down
bindkey -s '^[s' '^Asudo ^E' # alt+s
bindkey '^[j' join-lines # alt+j
bindkey '^[[3~' delete-char # del
bindkey '^[[1~' beginning-of-line # home
bindkey '^[[4~' end-of-line # end
bindkey '^[[Z' reverse-menu-complete # shift+tab
# prevent erroneous inputs from inputting anything.
bindkey '^[[3;5~' dummy # ctrl+del
bindkey '^[[5;5~' dummy # ctrl+PgUp
bindkey '^[[6;5~' dummy # ctrl+PgDn
bindkey '^[[5;6~' dummy # ctrl+shift+PgUp
bindkey '^[[6;6~' dummy # ctrl+shift+PgDn
bindkey '^[[3;2~' dummy # shift+del
bindkey '^[[1;2F' dummy # shift+end, do nothing, already at bottom (tmux)
bindkey '^[[6;2~' dummy # shift+PgDn, do nothing, already at bottom (tmux)
bindkey '^[[2;3~' dummy # alt+ins
bindkey '^[[3;3~' dummy # alt+del
bindkey '^[[5;3~' dummy # alt+PgUp
bindkey '^[[6;3~' dummy # alt+PgDn
bindkey '^[[2;4~' dummy # alt+shift+ins
bindkey '^[[3;4~' dummy # alt+shift+del
bindkey '^[[1;4H' dummy # alt+shift+home
bindkey '^[[1;4F' dummy # alt+shift+end
bindkey '^[[5;4~' dummy # alt+shift+PgUp
bindkey '^[[6;4~' dummy # alt+shift+PgDn
bindkey '^[[1;6q' dummy # ctrl+shift+1
bindkey '^[[1;6s' dummy # ctrl+shift+3
bindkey '^[[1;6t' dummy # ctrl+shift+4
bindkey '^[[1;6u' dummy # ctrl+shift+5
bindkey '^[[1;6w' dummy # ctrl+shift+7
bindkey '^[[1;6x' dummy # ctrl+shift+8
bindkey '^[[1;6y' dummy # ctrl+shift+9
bindkey '^[[1;6l' dummy # ctrl+shift+comma
bindkey '^[[1;6n' dummy # ctrl+shift+period
bindkey '^[[1;7A' dummy # ctrl+alt+arrow
bindkey '^[[1;7B' dummy # ctrl+alt+arrow
bindkey '^[[1;7C' dummy # ctrl+alt+arrow
bindkey '^[[1;7D' dummy # ctrl+alt+arrow
bindkey '^[[1;8A' dummy # ctrl+alt+shift+arrow
bindkey '^[[1;8B' dummy # ctrl+alt+shift+arrow
bindkey '^[[1;8C' dummy # ctrl+alt+shift+arrow
bindkey '^[[1;8D' dummy # ctrl+alt+shift+arrow
zle -N edit-command-line # new widget of the same function name
bindkey '^Xe' edit-command-line # ctrl+x -> e
# these drive letters were once to counteract my overzealous zsh completions.
hash -d c="/c"
hash -d d="/d"
[ -d /media/chibi ] && hash -d e="/media/chibi" || hash -d e="/e"
hash -d s="/s"
if [ -n "$MSYSTEM" ]; then
hash -d cyg=~c/cygwin/home/$USER
hash -d msys=~c/msys64/home/$USER
hash -d win=~c/Users/$USER
hash -d py=~win/Dropbox/py
else
hash -d py=~/Dropbox/py
fi
. ~/.shrc
alias -g OMFG="1>/dev/null" ### @ OMFG - silence stdout.
alias -g STFU="2>/dev/null" ### @ STFU - silence stderr.
alias -g SWAP="3>&1 1>&2 2>&3" ### @ SWAP - swap stdout and stderr. uses fd 3 as an intermediary.
alias -g WHOA='${whoa[@]}' ### @ WHOA - expand to several C/C++ flags to ease development.
alias -g WHEE='${whee[@]}' ### @ WHEE - WHOA but for C++ (specifically g++) only.
alias -g WELP='${welp[@]}' ### @ WELP - expand to C++ flags to enable a C++-as-C facade.
unalias 0x0.st
0x0.st() oxo "$@" # zsh hates the alias i set in .shrc, so use this instead
alias sc="~/sh/sc" # only runs in bash (for now), so be explicit with path
function {
# initialize prompts.
# zsh adds a % symbol to newline-less output, so my bash prompt is overkill
# NOTE: i've started hardcoding escapes instead of relying on zsh
# because detecting terminal features is too troublesome.
# https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_
local chset=$'\033\050B\017' # set G0 to USASCII charset and "shift-in" to it
local s=$'\033\133' # CSI
local e=m # SGR
local reset=$s$e
local curse=$s$'?25h' # show cursor (DECTCEM)
local good=42 # green
local bad=41 # red
case "${(L)HOST}" in
(neobanshee) good=46;; # cyan
(spectre) good=47;; # white
(wraith) good=43;; # yellow
(sabotage) good=45;; # magenta
esac
local t="${TERM%%-*}"
if [ "$t" = xterm ] || [ "$t" = screen ] || [ "$t" = tmux ]; then
# set window title
if [ "$t" = tmux ] # don't include host, tmux prepends it
then precmd() { print -Pn "\e]2;%~\a" }
else precmd() { print -Pn "\e]2;%M: %~\a" }
fi
elif [ "$t" = alacritty ]; then
# Alacritty-v0.13.2-portable.exe -t "MinGW x64" -e "usr/bin/env" PATH="/usr/local/sbin:/usr/local/bin:/usr/bin" MSYSTEM=MINGW64 TERM=alacritty shelly
precmd() {}
chset= # displays as U+263C for some reason
else
# act dumb
precmd() {}
PROMPT="%# "
return
fi
PROMPT="%{$chset$curse$reset$s%(?.$good.$bad);97$e%}%#%{$reset%} "
}
reload() { ### @-
### reload zsh by wiping temp files, recompiling rc files,
### and replacing the current process with a new zsh process.
# initctl has a "reload" symlink, but i'm already too used to typing this.
# to remedy this, when args are passed, invoke initctl instead.
if [ $# -gt 0 ]; then
"${commands[reload]:?initctl is missing}" "$@"
return # preserves $?
fi
if [ -n "$HOME" ] && cd -- "$HOME"; then
# this doesn't seem to help with _vim_files errors, eh.
# you wanna rm .zcompdump first, then exit. that's why!
[ -f .zshrc ] && zrecompile -p .zshrc
[ -f .prezto-compinit ] && zrecompile -p .prezto-compinit
rm -f .zcompdump .zshrc.zwc.old .zcompdump.zwc.old
fi
exec zsh # reload shell, inheriting environment
}
# generated by dircolors with https://github.com/isene/LS_COLORS
function {
# initialize colors for ls.
local lsc= line=
while read -r line; do
# strip any unprintable, non-ascii characters.
line="${line##*[! -~]}"
line="${line%%[! -~]*}"
lsc+="$line:"
done < ~/.ls_colors
export LS_COLORS="$lsc"
}
function {
local x=
# deprecated `for` syntax; who cares?
for x in ack cd cp ebuild gcc gist grep ln man mkdir mv rm
alias $x="nocorrect ${aliases[$x][@]:-$x}"
for x in ai arith curl fc find ftp hex history let locate \
rsync scp sftp tw twitch wget yt yt-dlp ytdl ytg
alias $x="noglob ${aliases[$x][@]:-$x}"
}
#zmodload zsh/complist # need all this
#autoload -Uz compinit && compinit # just for compdef
#compdef wat=which
#. ~/.prezto-compinit
! [ -e ~/.lol ] || . ~/.lol