forked from reorx/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
465 lines (380 loc) · 13.5 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
##############################################################################
# oh-my-zsh
##############################################################################
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
if [ "$TERM_PROGRAM" = "vscode" ]; then
ZSH_THEME="spaceship"
else
ZSH_THEME="spaceship"
fi
#ZSH_THEME="robbyrussell"
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
ZSH_CUSTOM=$HOME/.oh-my-zsh-custom
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=( autoenv2 )
source $ZSH/oh-my-zsh.sh
##############################################################################
# my zsh
##############################################################################
# Load other parts of zshrc
#source $HOME/.zshrc_os
# Load shell color
#SHELL_COLOR="$HOME/.shell-colors/base16-default.dark.sh"
#[[ -s $SHELL_COLOR ]] && source $SHELL_COLOR
function _timestamp_ms() {
if [[ "$(uname)" == "Darwin" ]]; then
echo $(gdate +%s%3N)
else
echo $(date +%s%3N)
fi
}
#RC_DEBUG="true"
RC_DEBUG="false"
if [[ $RC_DEBUG == "true" ]]; then
# source with timer
function source() {
local ts=$(_timestamp_ms)
builtin source $1
local te=$(_timestamp_ms)
echo "$(($te - $ts))ms: source $1"
}
# eval with timer
#function eval() {
# local ts=$(_timestamp_ms)
# builtin eval $1
# local te=$(_timestamp_ms)
# echo "$(($te - $ts))ms: eval $1"
#}
fi
#################
# Program Inits #
#################
# Load z
export _Z_DATA=$HOME/.z-data
source $HOME/.z/z.sh
# Python
if [ -e $HOME/.pythonrc.py ]; then
export PYTHONSTARTUP=$HOME/.pythonrc.py
fi
# virtualenv
export VIRTUAL_ENV_DISABLE_PROMPT="true"
# virtualenvwrapper
VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
if [ -e "$VIRTUALENVWRAPPER_SCRIPT" ]; then
export WORKON_HOME=$HOME/.venv
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source $VIRTUALENVWRAPPER_SCRIPT
fi
# pew (virtualenvwrapper alternative)
#type pew >/dev/null 2>&1 && source $(pew shell_config)
# fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_COMMAND='ag -l -g ""'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_DEFAULT_OPTS="--exact --no-mouse"
_fzf_compgen_path() {
ag -g "" "$1"
}
# tag
if (( $+commands[tag] )); then
export TAG_SEARCH_PROG=ag # replace with rg for ripgrep
tag() { command tag "$@"; source ${TAG_ALIAS_FILE:-/tmp/tag_aliases} 2>/dev/null }
alias ag=tag # replace with rg for ripgrep
fi
#########################
# Environment Variables #
#########################
# Prefer US English and use UTF-8
export LC_ALL="en_US.UTF-8"
export LANG=en_US.UTF-8
# ls colors, described as: foreground, background
# 1. directory: bold blue
# | 2. symbolic link: magenta
# | | 3. socket: red, bold blue
# | | | 4. pipe: black, bold blue
# | | | | 5. executable: red
# | | | | | 6. block special: default, bold blue
# | | | | | | 7. character special: light grey, bold blue
# | | | | | | | 8. executable with setuid bit set: light grey, bold red
# | | | | | | | | 9. executable with setgid bit set: black, bold brown
# | | | | | | | | | 10. directory writable to others, with sticky bit: black, bold green
# | | | | | | | | | | 11. directory writable to others, without sticky bit: black, brown
# | | | | | | | | | | |
export LSCOLORS=ExfxbEaEbxxEhEhBaDaCad
# Less
export LESSCHARSET=utf-8
export LESS='-R'
#export LESSOPEN='|~/.lessfilter %s'
export LESS_TERMCAP_mb=$(printf "\e[1;31m")
export LESS_TERMCAP_md=$(printf "\e[1;31m")
export LESS_TERMCAP_me=$(printf "\e[0m")
export LESS_TERMCAP_se=$(printf "\e[0m")
export LESS_TERMCAP_so=$(printf "\e[1;44;33m")
export LESS_TERMCAP_ue=$(printf "\e[0m")
export LESS_TERMCAP_us=$(printf "\e[1;32m")
# For more about termcap see:
# https://www.gnu.org/software/termutils/manual/termcap-1.3/html_chapter/termcap_4.html
# http://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized
export EDITOR=vim
# mosh
export MOSH_PREDICTION_DISPLAY=always
# httpstat
export HTTPSTAT_SHOW_BODY=false
export HTTPSTAT_SHOW_IP=true
export HTTPSTAT_SHOW_SPEED=true
export HTTPSTAT_SAVE_BODY=true
# csvless
export CSVLESS_MAX_COLUMN_WIDTH=64
export CSVLESS_LINE_NUMBERS=1
export CSVLESS_TABLE_STYLE=markdown
# exa
if [[ -x /usr/local/bin/exa ]]; then
alias ls='exa'
alias l='exa -lg --time-style=long-iso --git'
alias ll='exa -lga --time-style=long-iso --git'
# else
# alias ls='ls --color=auto -N'
# alias l='ls -lF --time-style=long-iso'
# alias ll='ls -alF --time-style=long-iso'
fi
#######
# zsh #
#######
# Disable autocorrect
unsetopt correct_all
# Auto rehash
#zstyle ":completion:*:commands" rehash 1
# History search
bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward
# SSH completion
zstyle ':completion:*:ssh-hosts' users-hosts $ssh_hosts
hosts=$(awk '/^Host / {printf("%s ",$2)}' ~/.ssh/config 2>/dev/null)
zstyle ':completion:*:hosts' hosts $ssh_hosts
#############
# Functions #
#############
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
[[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
zle end-of-line
}
zle -N sudo-command-line
bindkey "\e\e" sudo-command-line
#
#suite_virtualenv() {
# if [ -e .virtualenv ]; then
# name=$(cat .virtualenv)
# if [ $VIRTUAL_ENV ]; then
# if [ "$name" = "$(basename $VIRTUAL_ENV)" ]; then
# return
# fi
# fi
# workon $name
# fi
#}
#cd () {
# builtin cd "$@" && suite_virtualenv
#}
#suite_virtualenv
# Create a data URL from an image (works for other file types too, if you tweak the Content-Type afterwards)
function dataurl() {
echo "data:image/${1##*.};base64,$(openssl base64 -in "$1")" | tr -d '\n'
}
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}"
open "http://localhost:${port}/"
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn't break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
# Syntax-highlight JSON strings or files
function json() {
if [ -p /dev/stdin ]; then
# piping, e.g. `echo '{"foo":42}' | json`
python -mjson.tool | pygmentize -l javascript
else
# e.g. `json '{"foo":42}'`
python -mjson.tool <<< "$*" | pygmentize -l javascript
fi
}
# Get a character's Unicode code point
function codepoint() {
perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))"
echo # newline
}
function clean_pyc() {
find $1 -name '*.pyc' -exec rm {} \;
}
function sshch() {
# Options explaination
# q Quiet mode. Causes most warning and diagnostic messages to be suppressed.
# T Disable pseudo-tty allocation.
# N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
# D bind address to port
ssh -qTNv -D 7070 $@
}
function github-clone() {
git clone [email protected]:$1.git $2
}
function colortable() {
echo "use \\\x1B or \\\e as prefix, \\\x1B[0m as suffix"
for x in 0 1 4 5 7 8; do
for i in `seq 30 37`; do
for a in `seq 40 47`; do
echo -ne "\e[$x;$i;$a""m\\\x1B[$x;$i;$a""m\e[0;37;40m ";
done;
echo;
done;
done;
echo;
}
function colorcodes() {
T='gYw' # The test text
echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
done
echo;
done
echo
}
function colortable256() {
for i in {0..255} ; do
printf "\x1b[38;5;${i}mcolour${i}\n"
done
}
function curlhttpstat() {
curl -Ss -w'Timeline:
|
|--NAMELOOKUP %{time_namelookup}
|--|--CONNECT %{time_connect}
|--|--|--APPCONNECT %{time_appconnect}
|--|--|--|--PRETRANSFER %{time_pretransfer}
|--|--|--|--|--STARTTRANSFER %{time_starttransfer}
|--|--|--|--|--|--TOTAL %{time_total}
|--|--|--|--|--|--REDIRECT %{time_redirect}
Speed: %{speed_download} Bytes/s
' -o /dev/null $1
}
function urlencode() {
python -c 'import urllib, sys; print urllib.quote(sys.argv[1])' $1
}
function aws-du() {
aws s3 ls --summarize --human-readable --recursive s3://$@
}
function download_benchmark() {
DOWNLOAD_SPEED=`wget -O /dev/null $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}'`
echo "$DOWNLOAD_SPEED ($1)"
}
function tarczf() {
tar czf $1.tar.gz $1
}
function ips() {
curl ip.cn/$1
}
function py_find_packages() {
python -c 'from setuptools import find_packages; print find_packages()'
}
###########
# Aliases #
###########
alias c="echo -ne '\033c'"
alias lsd='ls -ld */'
#alias vim="nvim -p"
#alias ovim="/usr/local/bin/vim -p"
alias tree="tree --dirsfirst"
alias cleanpyc="find . -name '*.pyc' -exec rm {} \;"
alias cleanpycache="find . -type d -name '__pycache__' -prune -exec rm -r {} \;"
alias sa='_() { source activate $1 };_'
alias sd='source deactivate'
alias iota-seed="cat /dev/urandom |LC_ALL=C tr -dc 'A-Z9' | fold -w 81 | head -n 1"
alias jn="jupyter notebook"
alias urlencode='python -c "import sys, urllib.parse as ul; \
print(ul.quote_plus(sys.argv[1]))"'
alias urldecode='python -c "import sys, urllib.parse as ul; \
print(ul.unquote_plus(sys.argv[1]))"'
# Load local at last
if [ -e "$HOME/.zshrc_local" ]; then
source $HOME/.zshrc_local
fi
function options() {
PLUGIN_PATH="$HOME/.oh-my-zsh/plugins/"
for plugin in $plugins; do
echo "\n\nPlugin: $plugin"; grep -r "^function \w*" $PLUGIN_PATH$plugin | awk '{print $2}' | sed 's/()//'| tr '\n' ', '; grep -r "^alias" $PLUGIN_PATH$plugin | awk '{print $2}' | sed 's/=.*//' | tr '\n' ', '
done
}
setopt +o nomatch
###########
# Paths #
###########
export ANDROID_HOME="$HOME/Android/Sdk"
export ANDROID_EMULATOR="$ANDROID_HOME/emulator"
export ANDROID_TOOLS="$ANDROID_HOME/tools"
export ANDROID_PLATFORM_TOOLS="$ANDROID_HOME/platform-tools"
export PATH="$HOME/anaconda/bin:$PATH"
export PATH="$HOME/flutter/bin:$PATH"
export PATH="$ANDROID_EMULATOR:$PATH"
export PATH="$ANDROID_TOOLS:$PATH"
export PATH="$ANDROID_TOOLS/bin:$PATH"
export PATH="$ANDROID_PLATFORM_TOOLS/bin:$PATH"
# flutter
export PATH="$HOME/flutter/bin/cache/dart-sdk/bin:$PATH"
export PATH="$PATH":"$HOME/.pub-cache/bin"
if [ -d "/usr/local/cuda-10.0/bin/" ]; then
export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi
###########
# KeyBind #
##########
bindkey '^H' backward-kill-word
#settings
setopt extended_glob
# tabtab source for serverless package
# uninstall by removing these lines or running `tabtab uninstall serverless`
[[ -f /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/serverless.zsh ]] && . /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/serverless.zsh
# tabtab source for sls package
# uninstall by removing these lines or running `tabtab uninstall sls`
[[ -f /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/sls.zsh ]] && . /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/sls.zsh