-
Notifications
You must be signed in to change notification settings - Fork 0
/
_zshrc
executable file
·349 lines (275 loc) · 9.37 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
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block, everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Function path
# Prefer plugins instead of manual fpath settings
# fpath=(
# "$HOME/.zsh_completion/zchee_zsh-completions/src/go"
# "$HOME/.zsh_completion/zchee_zsh-completions/src/zsh"
# $fpath
# )
# PATH environment variables
export PATH=$HOME/bin:/usr/local/bin:$HOME/.local/bin:$PATH
# Path to oh-my-zsh installation.
export ZSH=/home/william/.oh-my-zsh
# Enable virtualenv prompt
export VIRTUAL_ENV_DISABLE_PROMPT=0
# Different options for virtual consoles
if [ "$TERM" = "linux" ]; then
ZSH_THEME="refined"
else
# ZSH_THEME="mytheme"
ZSH_THEME=powerlevel10k/powerlevel10k
fi
export EDITOR=vim
export VISUAL=vim
export BROWSER=google-chrome-stable
# Display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"
# Load oh-my-zsh plugins
plugins=(
git helm aws tmux fzf fzf-tab gitignore gcloud
dirhistory last-working-dir redis-cli z zsh-autosuggestions zsh-completions
)
# zsh-autosuggestions
export ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
export ZSH_AUTOSUGGEST_USE_ASYNC=true
export DISABLE_UPDATE_PROMPT=true
export DISABLE_MAGIC_FUNCTIONS=true
source $ZSH/oh-my-zsh.sh
autoload -U compinit && compinit
autoload -U select-word-style && select-word-style bash
# From zsh-syntax-highlighting package
# sudo pacman -S zsh-syntax-highlighting
# source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
###################
# Keybindings #
###################
# Use vi navigation keys in menu completion
zstyle ':completion:*' menu select
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
# Use CTRL+p and CTRL+n instead of arrow keys
bindkey "^p" up-line-or-beginning-search
bindkey "^n" down-line-or-beginning-search
# Adjust file listing colors for other-writables
export LS_COLORS="$LS_COLORS:ow=1;34;107:tw=1;34:"
###################
# Auto-completion #
###################
# AWS
if [ -f /usr/bin/aws_zsh_completer.sh ]; then
source /usr/bin/aws_zsh_completer.sh
fi
# Hashicorp Vault
if [ -x "$(command -v vault)" ]; then
complete -o nospace -C '/usr/bin/vault' vault
fi
# Alibaba Cloud https://github.com/aliyun/aliyun-cli
if [ -x "$(command -v aliyun)" ]; then
complete -o nospace -F '/home/william/bin/aliyun' aliyun
fi
# History
export HISTSIZE=10000000
export SAVEHIST=$HISTSIZE
#############
# Functions #
#############
# Query IP information
ipinfo() {
curl ipinfo.io/$1
}
# Kubectl get NodePort address
kubenp() {
# $1 namespace, $2 svc
NODE_PORT=$(kubectl get --namespace "$1" -o jsonpath="{.spec.ports[0].nodePort}" services "$2")
NODE_IP=$(kubectl get nodes --namespace "$1" -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
}
socks() {
if [[ -z "$(command -v tmux)" ]]; then
echo "Tmux is not installed"
return 1
fi
SOCKS_TMUX_SESSION_NAME=socks
tmux kill-session -t "$SOCKS_TMUX_SESSION_NAME" >/dev/null 2>&1
tmux new-session -s "$SOCKS_TMUX_SESSION_NAME" -d 'ssh -D 8080 william@arzhon-vps.arzhon.id'
tmux split-window -t "$SOCKS_TMUX_SESSION_NAME" -v 'iftop -c ~/.iftoprc -f "port ssh or port 2222"' # Need cap_net_raw=eip cap
tmux select-pane -t "$SOCKS_TMUX_SESSION_NAME:1.1"
tmux -2 attach-session -t "$SOCKS_TMUX_SESSION_NAME" -d
}
myxrandr() {
if [[ -z "$(command -v xrandr)" ]]; then
echo "Xrandr is not installed"
return 1
fi
if [ $# -ne 1 ]; then
echo "usage: $0 PRESET"
return 1
fi
MYXRANDR_PRESET="${1:-reset}"
case "$MYXRANDR_PRESET" in
reset)
xrandr -s 0
xrandr --auto
return 0
;;
home)
myxrandr reset
xrandr --output HDMI-0 --primary --auto
;;
work)
myxrandr reset
# xrandr --output DP1 -s 2560x1440 --primary --auto --output eDP1 --left-of DP1
# xrandr --output eDP1 --mode 1920x1080 --pos 0x0 --rotate normal --output DP1 --primary --mode 1920x1080 --pos 3840x0 --rotate normal --output HDMI1 --mode 1920x1080 --pos 1920x0 --rotate normal --output HDMI2 --off --output VIRTUAL1 --off
xrandr --output eDP1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output DP1 --off --output HDMI1 --mode 1920x1080 --pos 1920x0 --rotate normal --output HDMI2 --off --output VIRTUAL1 --off
;;
lt)
myxrandr reset
xrandr --output eDP1 --auto
;;
esac
echo "Using preset: $MYXRANDR_PRESET"
}
################
# Prompt setup #
################
kube() {
if (( ${+POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND} )); then
unset POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND
else
POWERLEVEL9K_KUBECONTEXT_SHOW_ON_COMMAND='kubectl|helm|kubens|kubectx|oc|istioctl|kogito|k9s|helmfile'
fi
p10k reload
if zle; then
zle push-input
zle accept-line
fi
}
export KUBE_PS1_ENABLED=off
kubeon() {
KUBE_PS1_ENABLED=on
p10k_reload
}
kubeoff() {
KUBE_PS1_ENABLED=off
p10k_reload
}
venvon() {
source ${1:-venv/bin/activate}
p10k_reload
}
venvoff() {
deactivate
p10k_reload
}
########################
# Other programs setup #
########################
# Alicloud
# source ~/.aliyun/.rc
# Go directory env
export GOPATH=/home/william/go
export GOBIN=/home/william/go/bin
export GOPRIVATE=github.com/tokopedia
export PATH=$GOBIN:$PATH
# Restic Backup Setup
export RESTIC_REPOSITORY=/run/media/william/HD-E1/backup/personal
# Ruby Setup. RVM to PATH for scripting. Make sure this is the last PATH variable change.
# export PATH="$PATH:$HOME/.rvm/bin"
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# Set up Node Version Manager
# export NVM_DIR="$HOME/.nvm"
# export NVM_SOURCE="/usr/share/nvm" # The AUR package installs it to here.
# [ -s "$NVM_SOURCE/nvm.sh" ] && . "$NVM_SOURCE/nvm.sh" # Load NVM
# Setup NPM user-wide installation, but are replaced by nvm specific
PATH="$HOME/.node_modules/bin:$PATH"
export npm_config_prefix=~/.node_modules
# Set up Composer
export PATH=$HOME/.config/composer/vendor/bin:$PATH
# Set up kubectl plugin krew
if [[ -x "$(command -v kubectl-krew)" ]]; then
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
fi
# Setup Terragrunt Cache Download Directory
export TERRAGRUNT_DOWNLOAD="$HOME/.terragrunt-cache"
# Wine
export BASE_WINEPREFIX64="$HOME/.wine-prefixes/64bit"
export BASE_WINEPREFIX32="$HOME/.wine-prefixes/32bit"
# Defaults
export WINEARCH="win64"
export WINEPREFIX="${BASE_WINEPREFIX64}/default"
# Naver Line
export WINE_LINE="WINEPREFIX=${BASE_WINEPREFIX64}/naver-line WINEARCH=win64"
alias winecfg-line="env $WINE_LINE winecfg"
alias winetricks-line="env $WINE_LINE winetricks line"
# Replace with ~/bin/wine-line script
# alias wine-line="dex ~/LINE.desktop"
# Gcloud (https://cloud.google.com/sdk/crypto#cloudsdk_python_sitepackages=1)
export CLOUDSDK_PYTHON_SITEPACKAGES=1
# Password Store
export PASSWORD_STORE_CHARACTER_SET='[:alnum:].,!?&*%_$#^@{}[]()<>=/\+'
###########
# Aliases #
###########
# Use neovim if available
if [[ -x "$(command -v nvim)" ]]; then
alias vim="nvim"
alias vi="nvim"
fi
# Ntfy to send push notification, token is stored in ~/.ntfy.yml
alias nf="ntfy"
# Mobile pushbullet
alias nfmb="ntfy -o device_iden ujviRNYx41csjwCSoo2Xx6 -b pushbullet"
# Yeecli to control Yee Lightbulb
alias yee="yeecli"
alias yeeb="yeecli brightness"
alias yeet="yeecli toggle"
alias yeew="yeecli rgb FFFFFF"
alias yeeo="yeecli rgb FFFFFF && yeecli temperature 4500"
alias yeer="yeecli rgb FF6600 && yeeb 50"
# Turn off display
alias dpoff="xset dpms force off"
# Suspend
alias spnd="systemctl suspend"
# Change dirs
alias cdgo="cd $GOPATH/src"
alias cdgoo="cd $GOPATH/src/github.com/williamchanrico"
alias cdgot="cd $GOPATH/src/github.com/tokopedia"
alias cdwork="cd ~/work"
# Better ls
alias ls="ls --color=auto --group-directories-first"
# Easy open from terminal
alias o="xdg-open"
# Sometimes used to bypass aliases
alias c="command"
# Terraform and Terragrunt
alias tf-auth="export GOOGLE_OAUTH_ACCESS_TOKEN=\$(gcloud auth print-access-token)"
alias tf="terraform"
alias tg-gcp="TERRAGRUNT_TFPATH=/usr/local/bin/terraform-0-12-13 terragrunt"
alias tg="TERRAGRUNT_TFPATH=terraform-v1.3.7 terragrunt-v0.42.7"
alias tg-tf-v1.0.6="TERRAGRUNT_TFPATH=terraform-v1.0.6 terragrunt-v0.32.4"
alias tg-tf-v1.0.7="TERRAGRUNT_TFPATH=terraform-v1.0.7 terragrunt-v0.32.4"
alias tg-tf-v1.1.3="TERRAGRUNT_TFPATH=terraform-v1.1.3 terragrunt-v0.32.4"
alias tg-tf-v1.2.1="TERRAGRUNT_TFPATH=terraform-v1.2.1 terragrunt-v0.32.4"
alias tg-tf-v1.3.7="TERRAGRUNT_TFPATH=terraform-v1.3.7 terragrunt-v0.42.7"
alias tg-tf-v1.5.72="TERRAGRUNT_TFPATH=terraform-v1.5.2 terragrunt-v0.48.0"
# Webcam Access
alias wcam="mpv --demuxer-lavf-format video4linux2 --demuxer-lavf-o-set input_format=mjpeg av://v4l2:/dev/video0"
# SQLFormat
alias sqlformat="sqlformat --reindent --keywords upper --identifiers lower"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
p10k_reload(){
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
}
p10k_reload
if [ -f "/opt/google-cloud-sdk/completion.zsh.inc" ]; then source "/opt/google-cloud-sdk/completion.zsh.inc"; fi
# Miniconda3
[ -f /opt/miniconda3/etc/profile.d/conda.sh ] && source /opt/miniconda3/etc/profile.d/conda.sh
# Kubectl
export USE_GKE_GCLOUD_AUTH_PLUGIN=True