-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
196 lines (171 loc) · 6.42 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
# Path to your oh-my-zsh installation.
# Remove redundant paths from $PATH variable
if [ -f "/tmp/MYPATH" ]; then
# init /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
# cleanup -/etc/paths -.zshrc -.zprofile -.bash_profile -.bashrc -.profile -/etc/profile -.zshenv
# typeset -U PATH
PATH=`cat /tmp/MYPATH`
\rm /tmp/MYPATH
else
echo $PATH > "/tmp/MYPATH"
fi
export ZSH=$HOME/.oh-my-zsh
export ZSH_LOCAL=$HOME/.zshrc_local
# Set name of the theme to load.
ZSH_THEME="amuse" # must be before source oh-my-zsh.sh
export SYSTEM=`uname -s`
# Add wisely, as too many plugins slow down shell startup.
if [ $SYSTEM = "Darwin" ] ; then
plugins=(git z command-not-found docker brew zsh-autosuggestions zsh-syntax-highlighting)
elif [ $SYSTEM = "Linux" ] ; then
plugins=(git z command-not-found docker systemd zsh-autosuggestions zsh-syntax-highlighting)
fi
source $ZSH/oh-my-zsh.sh
if [ $SYSTEM = "Darwin" ] ; then
# HomeBrew mirror, https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
export HOMEBREW_NO_AUTO_UPDATE=1
# JAVA_HOME
if command -v java > /dev/null 2>&1; then
# use java jdk, m1 use azul sdk https://www.azul.com/downloads/?package=jdk
# Install, http://www.oracle.com/java/technologies/downloads/
# UnInstall: https://www.java.com/en/download/help/mac_uninstall_java.html
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$PATH:$JAVA_HOME/bin
fi
fi
# Language setting
export PYTHONIOENCODING=UTF-8 # Fix python shell failed to write data to stream
export LANG=en_US.UTF-8 # You may need to manually set your language environment, include remote server
export LC_ALL=en_US.UTF-8 # Fix pipenv LC
export LESSCHARSET=utf-8 # Fix linux git diff and log chinese
# Zsh History
export HISTFILE=$HOME/.zsh_histfile # Where to save history.
export HISTSIZE=1000000 # How many lines in the current session to remember.
export SAVEHIST=1000000 # How many lines to save to disk. Must be <=HISTSIZE.
# Patterns to exclue. Separate with |. *-matching.
export HISTORY_IGNORE="(poweroff|reboot|halt|shutdown|xlogout|exit|who|fzf|pwd|gl|gst|gbr|gdc|gb)"
setopt HIST_IGNORE_SPACE # ignore duplicated commands history list
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS
# setopt SHARE_HISTORY # share command history data
# Zsh Autosuggest
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=110,underline"
# Path
export XDG_CACHE_HOME="$HOME/.cache/Microsoft/Python Language Server"
export SSH_KEY_PATH="$HOME/.ssh/id_rsa"
# export WORKER_SSH_KEY_PATH="$HOME/.ssh/id_rsa"
# Fix Neovim mypy flake8 yapf isort bin path
export PATH="$HOME/bin:$HOME/workspace/neovim3/bin:$PATH"
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
# Pyenv
if [ -d "$HOME/.pyenv" ]; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PYTHON_BUILD_MIRROR_URL="https://pyenv.ibeats.top"
eval "$(pyenv init -)"
eval "$(pyenv init --path)"
# eval "$(pyenv virtualenv-init -)"
fi
# Golang
if command -v go >/dev/null 2>&1; then
export GOPATH="$HOME/workspace/go" # Golang Path
export PATH="$GOPATH/bin:$PATH"
export GOPROXY=https://goproxy.cn
export GO111MODULE=on
fi
if [ -d "$HOME/.cargo" ]; then
export PATH="$HOME/.cargo/bin:$PATH"
#export RUSTUP_DIST_SERVER="https://mirrors.tuna.tsinghua.edu.cn/rustup"
fi
# Pipenv
if command -v pipenv >/dev/null 2>&1; then
#export PIPENV_PYPI_MIRROR="https://pypi.doubanio.com/simple/"
export PIPENV_IGNORE_VIRTUALENVS=1
export PIPENV_VERBOSITY=-1
# load very slow
# eval "$(pipenv --completion)"
fi
# Fzf
if [ -f "$HOME/.fzf.zsh" ]; then
# ctrl-t:fzf-file-widget
# ctrl-r:serach-zsh-history
# ctrl-x:open in nvim(split)
export FZF_DEFAULT_COMMAND='ag -i -U --hidden -g ""'
export FZF_DEFAULT_OPTS="--no-mouse --height 40% --layout=reverse --border --prompt '>>>' \
--bind 'alt-j:preview-down,alt-k:preview-up,ctrl-v:execute(nvim {})+abort,ctrl-y:execute-silent(cat {} | pbcopy)+abort,?:toggle-preview' \
--header 'A-j/k: preview down/up, C-v: open in nvim(vsplit), C-y: copy, ?: toggle preview' \
--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -100'"
source $HOME/.fzf.zsh
fi
# System software alias
#if which nvim 2>&1 > /dev/null; then
if command -v nvim >/dev/null 2>&1; then
alias vi=nvim
elif command -v vim >/dev/null 2>&1; then
alias vi=vim
else
alias vi=vi
fi
alias ssh='ssh -A'
alias df='df -h'
alias du='du -h -d 1' # Path Deep
alias last='last -n 10' # last login
alias now='date +"%Y-%m-%d %T"'
alias pg='ps -ef | grep'
alias ports='netstat -tulanp'
alias pong='ping -c 5 ' # Ping limited
alias tailf='tail -f'
alias reload='source $HOME/.zshrc'
# Git alias
alias gup="git branch | awk '/^\\* / { print \$2 }' | xargs -I {} git branch --set-upstream-to=origin/{} {}"
alias gll="git stash && git pull origin $(git_current_branch) && git stash pop"
alias gdc="git dc"
# Other alias
alias tn='tmux -2 new -s'
alias ta='tmux -2 attach -t' # -2 Force tmux to assume the terminal supports 256 colours.
alias rm=safe_rm
alias cp=smart_cp
alias sed=super_sed
alias weather='curl wttr.in/~上海'
alias myip='curl https://myip.ipip.net' # 'curl myip.ibeat.top' # 'https://ipinfo.io/plain;echo'
alias iplocation="_f(){ curl http://cip.cc/\$1; }; _f" # freeapi.ipip.net/{ip}
alias rmpyc='find . -name "*.pyc" -exec rm -rf {} \; >> /dev/null 2>&1' # 递归删除目录下所有pyc
alias resdns='dscacheutil -flushcache'
alias netlisten='lsof -i -P | grep -i "listen"'
alias worker-agent='ssh-add $HOME/.ssh/id_rsa' # ssh-agent zsh, eval `ssh-agent -s`
alias cvenv='virtualenv -p `which python3` venv; source venv/bin/activate'
alias avenv='source venv/bin/activate'
#alias pip=pipenv
alias pps='pipenv shell'
alias vo='vi -o$#'
alias clntrash='\rm -rf $HOME/.trash/*'
# Docker alias
alias dorkrmall='docker ps --all | tail -n 8 | awk -F ' ' '{print $1}' | xargs docker rm'
# Toggle vim, usage ^z
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
# Load local zsh env
if [ -f $ZSH_LOCAL ]; then
source $ZSH_LOCAL
fi
function auto_pipenv_shell {
if [ ! -n "${PIPENV_ACTIVE+1}" ]; then
if [ -f "Pipfile" ] ; then
pipenv shell
fi
fi
}
function cd {
builtin cd "$@"
auto_pipenv_shell
}
auto_pipenv_shell