-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
344 lines (280 loc) · 7.27 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
# -------------------
# General Settings
# -------------------
bindkey -e
# --------------------
# Adding fpath
# --------------------
# homebrew
case ${OSTYPE} in
darwin*)
eval "$(/opt/homebrew/bin/brew shellenv)"
;;
linux*)
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
;;
esac
if type brew &>/dev/null
then
fpath=($(brew --prefix)/share/zsh/site-functions $fpath)
fi
# import completions
fpath=(~/.zsh/completion $fpath)
# -------------------
# Enable Completion
# -------------------
autoload -U +X bashcompinit && bashcompinit
autoload -Uz compinit && compinit
# -------------------
# Add Zsh Hook
# -------------------
autoload -Uz add-zsh-hook
# -------------------
# Recent Directories
# -------------------
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':completion:*' recent-dirs-insert both
zstyle ':chpwd:*' recent-dirs-prune parent
autoload -Uz chpwd_recent_dirs cdr
add-zsh-hook chpwd chpwd_recent_dirs
# -------------------
# Other Settings
# -------------------
# suppress prompt
export LISTMAX=10000
# history
export HISTFILE=$HOME/.zsh_history
export HISTSIZE=10000
export SAVEHIST=10000
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_SAVE_NO_DUPS
setopt HIST_NO_STORE
setopt HIST_IGNORE_SPACE
setopt HIST_REDUCE_BLANKS
setopt SHARE_HISTORY
setopt AUTO_PUSHD
setopt AUTO_CD
setopt PUSHD_IGNORE_DUPS
zshaddhistory() {
local line=${1%%$'\n'}
local cmd=${line%% *}
# Only those that satisfy all of the following conditions are added to the history
[[ ${#line} -ge 5
&& ${cmd} != ls
&& ${cmd} != cd
&& ${cmd} != cdr
&& ${cmd} != more
&& ${cmd} != less
&& ${cmd} != ping
&& ${cmd} != which
]]
}
# autopair
source $(brew --prefix)/share/zsh-autopair/autopair.zsh
# coreutils
alias ln="gln"
alias wc="gwc"
# pipe
alias -g C='| wc -l'
alias -g G='| grep'
alias -g H='| head'
alias -g L='| less'
alias -g M='| more'
alias -g T='| tail'
alias -g J='| jq'
alias -g Y='| yq'
# cd
alias c="cd"
alias ...="cd ../.."
# lsd
alias l="ls"
alias ll="ls -la"
alias ls="lsd"
# vim
alias v="nvim"
alias vim="nvim"
# Default Editor
export EDITOR=$(which nvim)
# XDG
export XDG_CONFIG_HOME=$HOME/.config
# Git
export GPG_TTY=$TTY
alias g="git"
alias cr='cd "$(git rev-parse --show-toplevel)"'
alias ga="git add"
alias gpl="git pull"
alias gplr="git pull --rebase origin"
alias gst="git stash -u"
alias gsta="git stash apply"
alias gcm="git commit -m"
alias gco="git checkout"
alias gsw="git switch"
alias gps="git push"
alias gpsf="git push --force-with-lease"
alias glgo="git log --oneline"
alias gcom="git switch \$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)"
alias gplrm="git pull --rebase origin \$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)"
alias ghs="gh api -X GET /user/starred --paginate --cache 24h | jq '.[].full_name' -r | fzf | xargs gh repo view --web"
# GitHub
alias ghb="gh browse"
alias ghpw="gh pr view --web"
alias ghpc="gh pr create"
# Kubernetes
alias k="kubectl"
alias kg="kubectl get"
alias kd="kubectl describe"
alias kl="kubectl logs"
alias kt="kubectl top"
alias kr="kubectl rollout"
type kubectl >/dev/null 2>&1 && source <(kubectl completion zsh)
# stern
type stern >/dev/null 2>&1 && source <(stern --completion=zsh)
# k9s
alias k9="k9s --readonly"
# Terraform
alias tf="terraform"
alias tff="terraform fmt"
alias tfp="terraform plan"
alias tfa="terraform apply"
alias tfs="terraform state"
export TF_CLI_ARGS_plan="--parallelism=30"
export TF_CLI_ARGS_apply="--parallelism=30"
# Go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH
# Java
export PATH=$(brew --prefix)/opt/openjdk@11/bin:$PATH
export CPPFLAGS="-I/opt/homebrew/opt/openjdk@11/include"
# deno
export PATH=$HOME/.deno/bin:$PATH
# deno tools
if [ $commands[switchbot] ]; then
source <(switchbot completions zsh)
fi
# Python
export PATH=/opt/homebrew/Cellar/[email protected]/3.8.19/Frameworks/Python.framework/Versions/3.8/bin:$PATH
# Rust
export PATH=$HOME/.cargo/bin:$PATH
# VSCode
alias e='code -a .'
# gcloud
test -e $HOME/google-cloud-sdk/path.zsh.inc && source $HOME/google-cloud-sdk/path.zsh.inc || true
test -e $HOME/google-cloud-sdk/completion.zsh.inc && source $HOME/google-cloud-sdk/completion.zsh.inc || true
export USE_GKE_GCLOUD_AUTH_PLUGIN=true
export CLOUDSDK_PYTHON=$(which python3.9)
# direnv
type direnv >/dev/null 2>&1 && source <(direnv hook zsh)
export DIRENV_LOG_FORMAT=
# tencent
export PATH=$HOME/.tencent/bin:$PATH
# tccli
complete -C 'tccli_completer' tccli
# terraform
complete -o nospace -C terraform terraform
# Node.js
alias nr="npm run"
# aqua
export PATH="$(aqua root-dir)/bin:$PATH"
export AQUA_GLOBAL_CONFIG=$HOME/.config/aqua/aqua.yaml
export NPM_CONFIG_PREFIX=${XDG_DATA_HOME:-$HOME/.local/share}/npm
export PATH=$NPM_CONFIG_PREFIX/bin:$PATH
# iterm2
test -e $HOME/.iterm2_shell_integration.zsh && source $HOME/.iterm2_shell_integration.zsh || true
# wsl
export LD_LIBRARY_PATH=/usr/lib/wsl/lib:$LD_LIBRARY_PATH
# lovot
export PATH=$HOME/.lovot/bin:$PATH
if [ $commands[lovot] ]; then
source <(lovot completion zsh)
fi
# -------------------
# Functions
# -------------------
function ghq-fzf() {
local src=$(ghq list | fzf --height 40% --reverse)
if [ -n "$src" ]; then
BUFFER="cd $(ghq root)/$src"
zle accept-line
fi
zle -R -c
}
zle -N ghq-fzf
bindkey '^]' ghq-fzf
function cdr-fzf() {
local src=$(cdr -l | awk '{print $2}' | fzf --height 40% --reverse)
if [ -n "$src" ]; then
BUFFER="cd $src"
zle accept-line
fi
zle -R -c
}
zle -N cdr-fzf
bindkey '^z' cdr-fzf
local no_expand_commands=("ls" "ll" "ln" "wc")
function expand-alias() {
local words=(${(z)LBUFFER})
local word="${words[-1]}"
if [[ ! "${no_expand_commands[(r)$word]}" ]]; then
zle _expand_alias
fi
zle self-insert
}
zle -N expand-alias
bindkey -M main ' ' expand-alias
function expand-alias-accept-line() {
local words=(${(z)LBUFFER})
local word="${words[-1]}"
if [[ ! "${no_expand_commands[(r)$word]}" ]]; then
zle _expand_alias
fi
zle .reset-prompt
zle .accept-line
}
zle -N accept-line expand-alias-accept-line
function paste-as-yank() {
BUFFER=$(pbpaste)
CURSOR=$#BUFFER
zle redisplay
}
zle -N paste-as-yank
bindkey "^y" paste-as-yank
# -------------------
# Before Load Plugins
# -------------------
# zsh-autocomplete
zstyle ':autocomplete:*' fzf-completion yes
zstyle -e ':autocomplete:*:*' list-lines 'reply=( $(( LINES / 3 )) )'
zstyle ':autocomplete:history-*:*' list-lines 5
zstyle ':autocomplete:*' delay 0
zstyle ':autocomplete:*' min-input 1
# See: https://github.com/marlonrichert/zsh-autocomplete/issues/724
setopt INTERACTIVECOMMENTS
# -------------------
# Load Plugins
# -------------------
eval "$(sheldon source)"
# -------------------
# Starship
# -------------------
eval "$(starship init zsh)"
# -------------------
# fzf
# -------------------
eval "$(fzf --zsh)"
# catppuccin
# See: https://github.com/catppuccin/fzf
export FZF_DEFAULT_OPTS=" \
--layout=reverse \
--color=bg+:#313244,bg:#1e1e2e,spinner:#f5e0dc,hl:#f38ba8 \
--color=fg:#cdd6f4,header:#f38ba8,info:#cba6f7,pointer:#f5e0dc \
--color=marker:#f5e0dc,fg+:#cdd6f4,prompt:#cba6f7,hl+:#f38ba8"
# -------------------
# zeno.zsh
# -------------------
if [[ -n $ZENO_LOADED ]]; then
source $ZENO_ROOT
bindkey '^i' zeno-completion
bindkey '^x ' zeno-insert-space
bindkey '^x^m' accept-line
fi