-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshrc.min
443 lines (364 loc) · 12.5 KB
/
.zshrc.min
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
config_help=false
zshrc_setup_completion() {
zstyle ':completion:*' auto-description '\ %d'
# Removed: _list
# Was ruining menucomplete
zstyle ':completion:*' completer _expand _complete _ignored _match _correct _approximate _prefix
zstyle ':completion:*' format '> Completing %d ...'
zstyle ':completion:*' insert-unambiguous true
zstyle ":completion:*:default" list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'l:|=* r:|=*'
zstyle ':completion:*' max-errors 4
zstyle ':completion:*' menu select=1
zstyle ':completion:*' original true
zstyle ':completion:*' preserve-prefix '//[^/]##/'
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*' verbose true
zstyle ':completion:*' rehash true
zstyle :compinstall filename '/home/max/.zshrc'
}
zshrc_autoload() {
autoload -Uz compinit
compinit
autoload -Uz promptinit
promptinit
autoload -Uz edit-command-line
if ( $config_help ); then
autoload -Uz run-help
alias help=run-help
autoload -Uz run-help-git
autoload -Uz run-help-ip
autoload -Uz run-help-openssl
autoload -Uz run-help-p4
autoload -Uz run-help-sudo
autoload -Uz run-help-svk
autoload -Uz run-help-svn
fi
}
zshrc_source() {
if [[ -e "$HOME/.batsrc" ]]; then
source "$HOME/.batsrc"
fi
if [[ -d "$HOME/.neovim-studio/" ]] && [[ -z "${NEOVIM_STUDIO_PROFILE_SOURCED}" ]]; then
source "$HOME/.profile"
if [[ -z "${NEOVIM_STUDIO_PROFILE_SOURCED}" ]]; then
# Doesn't exist within the profile.
export NEOVIM_STUDIO_PROFILE_SOURCED=1
fi
fi
if [ -f "${HOME}/.zplug/repos/junegunn/fzf/shell/key-bindings.zsh" ]; then
# fzf searches for this, so leave it as it is.
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
fi
if [[ -e "$HOME/src/robobenklein-config/zsh/plunks/rtabfunc.zsh" ]]; then
source "$HOME/src/robobenklein-config/zsh/plunks/rtabfunc.zsh"
fi
}
zshrc_set_options() {
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=10000
# man zshoptions
setopt correct
#setopt correctall
setopt clobber
setopt interactivecomments
setopt nomatch
setopt extendedglob
setopt listpacked
setopt menucomplete
setopt sharehistory
setopt appendhistory
setopt autocd
setopt beep
setopt notify
# Vim Bindings
bindkey -v
bindkey '^a' beginning-of-line
bindkey '^e' end-of-line
bindkey '^P' up-history
bindkey '^N' down-history
bindkey '^h' backward-delete-char
bindkey '^w' backward-kill-word
bindkey '^r' history-incremental-search-backward
bindkey '^[[Z' reverse-menu-complete
zle-keymap-select () {
zle reset-prompt
zle -R
}
zle -N zle-keymap-select
export KEYTIMEOUT=1
}
zshrc_zplug() {
if [[ ! -d "$HOME/.zplug" ]]; then
curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh
fi
if [[ -d "$HOME/.zplug" ]]; then
source "$HOME/.zplug/init.zsh"
zplug "zplug/zplug", hook-build: "zplug --self-manage"
zplug "zsh-users/zsh-history-substring-search"
zplug "zsh-users/zsh-autosuggestions"
zplug "zsh-users/zsh-completions"
zplug "mfaerevaag/wd", as:command, use:"wd.sh", \
hook-load:"wd() { . $ZPLUG_REPOS/mfaerevaag/wd/wd.sh }"
zplug "arzzen/calc.plugin.zsh"
zplug "chrissicool/zsh-256color"
zplug "hlissner/zsh-autopair", defer:2
# Improved bash compatibility
# zplug "chrissicool/zsh-bash"
zplug "stackexchange/blackbox"
zplug "tarrasch/zsh-command-not-found"
zplug "junegunn/fzf", as:command, rename-to:fzf, \
hook-build:"rm ~/.fzf.zsh; ./install --all && source ${HOME}/.fzf.zsh"
# Install fzf or fzy
zplug "b4b4r07/enhancd", use:init.sh, hook-load:"ENHANCD_DISABLE_DOT=1"
# git log = glo; git diff = gd; git add = ga; git ignore = gi
zplug "wfxr/forgit", defer:1
export NVM_LAZY_LOAD=true
export NVM_CACHE_LOAD=true
# zplug "lukechilds/zsh-nvm"
zplug "maxattax97/zsh-nvm"
zplug "gko/ssh-connect", as:command
# zplug "bhilburn/powerlevel9k", use:powerlevel9k.zsh-theme
zplug "supercrabtree/k"
zplug "psprint/zsh-navigation-tools"
# Must load last.
# zplug "zsh-users/zsh-syntax-highlighting"
zplug "zdharma/fast-syntax-highlighting", defer:3
if ! zplug check; then
zplug install
fi
zplug load
else
echo "Failed to load zplug plugins."
fi
}
zshrc_set_path() {
add_path() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="${PATH:+"$PATH:"}$1"
fi
}
add_path "${HOME}/bin/"
add_path "${HOME}/.local/bin/"
add_path "/sbin/"
add_path "/usr/sbin/"
add_path "${HOME}/.SpaceVim/bin/"
add_path "${HOME}/src/depot_tools/"
add_path "${HOME}/.anaconda2/bin/"
add_path "${HOME}/anaconda2/bin/"
add_path "${HOME}/src/cquery/build/release/bin/"
add_path "${HOME}/.adb-fastboot/platform-tools/"
}
zshrc_load_library() {
# Join a telnet based movie theater.
starwars() {
telnet towel.blinkenlights.nl
}
# Download and run a curl based Party Parrot animation.
parrot() {
curl parrot.live
}
# Duplicate of parrot()
party() {
parrot
}
# Login and play/watch Nethack from anywhere.
nethack() {
telnet nethack.alt.org
}
# Aliases, functions, commands, etc.
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "Unknown filetype for '$1'" ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# Host the current directory via HTTP
hostdir() {
if type "python3" > /dev/null 2>&1; then
python3 -m http.server
elif type "python" > /dev/null 2>&1; then
python -m SimpleHTTPServer
fi
}
# Type a string of text letter by letter.
typewriter() {
local message="$1"
local i=0
while [ "$i" -lt "${#message}" ]; do
echo -n "${message:$i:1}"
sleep 0.05
i="$((i + 1))"
done
printf "\n"
}
translate() {
gawk -f <(curl -Ls git.io/translate) -- -shell
}
repair_nvidia() {
if type "zypper" > /dev/null 2>&1; then
sudo zypper in -f nvidia-gfxG05-kmp-default
fi
}
mapscii() {
telnet mapscii.me
}
bomb() {
bomb | bomb &
}
tone() {
(speaker-test --frequency $1 --test sine > /dev/null 2>&1) &
pid=$!
sleep 0.${2}s
kill -13 $pid
}
waitonline() {
echo "Waiting for online access ..."
failing=true
while "$failing"; do
ping 8.8.8.8 -c 1 -W 2 > /dev/null 2>&1
success="$?"
if [ "$success" -eq 0 ]; then
printf "\n"
echo "Internet access has been restored!"
notify-send --urgency=normal --icon=gtk-network "Online" "Internet access has been restored."
tone 500 400; tone 1000 400; tone 2000 400
failing=false
else
printf "."
sleep 1
fi
done
}
dockerclean() {
echo "Cleaning Docker images and containers ..."
sudo docker rm $(sudo docker ps -a -q)
sudo docker rmi $(docker images -q)
echo "Docker cleaned."
}
}
zshrc_set_aliases() {
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Fix tmux 256 colors:
alias tmux='tmux -2'
# Clear color codes before clearing:
alias clear='echo -e "\e[0m" && clear'
# Typical rsync command
alias relocate='rsync -avzh --info=progress2'
}
zshrc_set_default_programs() {
# For heavyweight purposes.
if [[ -x "$(command -v nvim)" ]]; then
export VISUAL="/usr/bin/nvim"
if [[ -d "${HOME}/.SpaceVim" ]]; then
alias vim="nvim"
fi
elif [[ -x "$(command -v vim)" ]]; then
export VISUAL="/usr/bin/vim"
alias nvim="vim"
else
export VISUAL="/usr/bin/nano"
fi
# For lightweight purposes.
export EDITOR="$VISUAL"
export PAGER="less"
export MANPAGER="less"
if [[ -x "$(command -v firefox)" ]]; then
export BROWSER="firefox"
elif [[ -x "$(command -v chromium)" ]]; then
export BROWSER="chromium"
elif [[ -x "$(command -v google-chrome-stable)" ]]; then
export BROWSER="google-chrome-stable"
fi
if [[ -x "$(command -v urxvt-256color)" ]]; then
export TERMINAL="$(which urxvt-256color)"
elif [[ -x "$(command -v konsole)" ]]; then
export TERMINAL="$(which konsole)"
fi
export P4IGNORE="/home/max/Perforce/mocull/Engineering/Software/Linux/Code/.p4ignore"
}
zshrc_set_environment_variables() {
CPU_CORES="$(grep "^core id" /proc/cpuinfo | sort -u | wc -l)"
CPU_THREADS="$(grep "^core id" /proc/cpuinfo | sort -u | wc -l)"
if [[ -d "${HOME}/Perforce/mocull/Engineering/Software/Linux/Code/AATSV4/Lib" ]]; then
export NODE_PATH="${NODE_PATH}:${HOME}/Perforce/mocull/Engineering/Software/Linux/Code/AATSV4/Lib"
fi
if [[ -s "${HOME}/Perforce/mocull/Engineering/Software/Linux/Code/.p4ignore" ]]; then
export P4IGNORE="${HOME}/Perforce/mocull/Engineering/Software/Linux/Code/.p4ignore"
fi
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/home/max/.anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "${HOME}/.anaconda3/etc/profile.d/conda.sh" ]; then
. "${HOME}/.anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="${PATH}:${HOME}/.anaconda3/bin"
\export PATH="${PATH}:${HOME}/anaconda3/bin"
fi
fi
unset __conda_setup
# <<< conda init <<<
if [[ -d "/usr/lib/oracle/12.1/client64" ]]; then
export ORACLE_HOME="/usr/lib/oracle/12.1/client64"
export PATH="${PATH}:${ORACLE_HOME}/bin"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ORACLE_HOME}/lib"
fi
# Gentoo users say number of threads + 1 -- this fills out the maximal amount of CPU usage.
# Number of cores alone leaves enough CPU to process other things... like a desktop environment.
export MAKEFLAGS="${MAKEFLAGS} -j${CPU_CORES}"
}
zshrc_init() {
zshrc_benchmark_start
zshrc_detect_term_colors
zshrc_display_banner
zshrc_source
zshrc_set_path
zshrc_set_aliases
zshrc_set_default_programs
zshrc_set_environment_variables
zshrc_load_library
zshrc_setup_completion
zshrc_set_options
zshrc_autoload
zshrc_powerlevel9k
zshrc_zplug
zshrc_benchmark_stop
}
zshrc_init