forked from pqiaohaoq/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
238 lines (203 loc) · 6.02 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
# Variable behaviors
setopt NO_ALL_EXPORT # Don't export all variables to environment
# completion
setopt MENU_COMPLETE # Cycle through completions by completing in place
setopt NO_LIST_BEEP # Prevent beeping on ambiguous completion
# Globbing
setopt EXTENDED_GLOB # Allow globbing qualifiers and other extensions
setopt COMPLETE_IN_WORD
setopt GLOB_DOTS # Patterns may match without leading periods
setopt NOMATCH # Throw error if a glob fails to match
# Background jobs
setopt AUTO_CONTINUE # Ensure a stopped job is continued when disowned
setopt NO_BG_NICE # Don't lower priority of background jobs
# Miscellaneous
setopt nocorrectall # not to correct command
setopt NO_BEEP # Do not beep on line editor errors
bindkey -v # use vi mode to bind keys
# Disable core dumps
limit coredumpsize 0
# History behavior
setopt INC_APPEND_HISTORY
setopt HIST_IGNORE_DUPS
setopt HIST_FIND_NO_DUPS
setopt NO_HIST_BEEP
setopt HIST_IGNORE_SPACE
setopt HIST_REDUCE_BLANKS
setopt NO_HIST_VERIFY
setopt BANG_HIST
setopt INTERACTIVE_COMMENTS
zshaddhistory() { whence ${${(z)1}[1]} >| /dev/null || return 1 } # Don't save failed commands
export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=50000
export SAVEHIST=10000
# ========================
# X Display For Arch Linux
# ========================
if [[ "$(uname -s)" = "Linux" && ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
command -v startx > /dev/null 2>&1 && exec startx
fi
if [ "$TERM" = "xterm-termite" ]; then
export TERM=xterm-256color
fi
# ========================
# Environments
# ========================
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
export CLICOLOR=1
export GPG_TTY=$(tty)
if [[ $(command -v nvim) ]]; then
export EDITOR=nvim
else
export EDITOR=vi
fi
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_AUTO_UPDATE=true
export HOMEBREW_EDITOR=nvim
export GO111MODULE=on
export GOPATH=$HOME/.go
export GOBIN=$GOPATH/bin
if [[ $(command -v go) ]]; then
export GOROOT=$(go env GOROOT)
fi
export PATH=$PATH:/usr/local/sbin:$HOME/.node_modules/bin:$GOPATH/bin:$HOME/.local/bin:/opt/miniconda3/bin
# Mirrors
export GOPROXY=https://mirrors.aliyun.com/goproxy/
export NODE_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
# ========================
# Zplug
# ========================
# Check if zplug is installed
if [[ ! -d ~/.zplug ]]; then
git clone https://github.com/zplug/zplug ~/.zplug
fi
source $HOME/.zplug/init.zsh
zplug "zdharma/fast-syntax-highlighting"
zplug "zsh-users/zsh-autosuggestions"
zplug "tinyRatP/ys", as:theme
if ! zplug check; then
zplug install
fi
zplug load
# ========================
# Alias
# ========================
alias zshconfig="source ~/.zshrc"
alias ls="lsd"
alias l="ls -hl"
alias la="ls -ahl"
alias du="ncdu --color dark -rr -x --exclude .git"
alias share="python3 -m http.server"
if type nvim > /dev/null 2>&1; then
alias vim='nvim'
alias vi='nvim'
fi
# ========================
# fzf custom-functions
# ========================
# brew management
function cask() {
local token
token=$(brew search --casks | fzf-tmux --query="$1" +m --preview 'brew cask info {}')
if [ "x$token" != "x" ]
then
echo "(I)nstall or open the (h)omepage of $token"
read input
if [ $input = "i" ] || [ $input = "I" ]; then
brew cask install $token
fi
if [ $input = "h" ] || [ $input = "H" ]; then
brew cask home $token
fi
fi
}
function install() {
local inst=$(brew search | fzf -m)
if [[ $inst ]]; then
for prog in $(echo $inst); do
brew install $prog
done
fi
}
function rmtree() {
local uninstall=$(brew leaves | fzf -m)
if [[ $uninstall ]]; then
for prog in $(echo $uninstall); do
brew rmtree $prog
done
fi
}
function zap() {
local uninstall=$(brew cask list | fzf -m)
if [[ $uninstall ]]; then
for prog in $(echo $uninstall); do
brew cask zap $prog
done
fi
}
# Command Support
function fh() {
eval $( (fc -l 1 || history) | fzf +s +x --tac --height 20% | sed 's/ *[0-9]* *//')
}
function sssh() {
local ssh_name=$(awk '/Host / { for(i=2;i<=NF;i++) printf "%s\n", $i }' $HOME/.ssh/config | fzf -m --height 20%)
if [[ $ssh_name ]]; then
ssh $ssh_name
fi
}
# Auto-generate .gitignore from gitignore.io
function __git() {
curl -L -s https://gitignore.io/api/"$@"
}
function gi() {
if [ "$#" -eq 0 ]; then
IFS+=","
for item in $(__git list); do
echo $item
done | fzf --height 20% --multi --ansi | paste -s -d "," - |
{ read result && __git "$result" ; } > ./.gitignore
else
__git "$@" > ./.gitignore
fi
}
# Tmux Management
function tm() {
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
if [[ $1 ]]; then
tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
fi
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No session found."
}
# HTTP Proxy
function proxy() {
if [[ ! ${http_proxy} ]]; then
export http_proxy=http://127.0.0.1:1087
export https_proxy=$http_proxy
fi
}
# Kill Process
function fkill() {
local pid
if [ "$UID" != "0" ]; then
pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
else
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
fi
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi
}
# Backup Arch_Linux System
function backup_arch() {
sudo rsync -aAXvP --delete --exclude=/dev/* --exclude=/proc/* --exclude=/sys/* --exclude=/tmp/* --exclude=/run/* --exclude=/mnt/* --exclude=/media/* --exclude=/lost+found --exclude=/home/.ecryptfs / $1
}
# Generate .Pacmanfile
function pacmanfile() {
comm -23 <(yay -Qqt | sort) <(yay -Sqg base base-devel | sort) > $HOME/.Pacmanfile
}
function brewfile() {
brew bundle dump --global -f
}