-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_zshrc
executable file
·277 lines (218 loc) · 7.54 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
# Oh-my-zsh installation path
ZSH=/usr/share/oh-my-zsh/
# Enable virtualenv prompt
export VIRTUAL_ENV_DISABLE_PROMPT=0
# PATH environment variables
export PATH=$HOME/bin:/usr/local/bin:$HOME/.local/bin:$PATH
# Display red dots whilst waiting for completion.
export COMPLETION_WAITING_DOTS="true"
# Keyring │ │
export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/gcr/ssh
# Powerlevel10k theme path
source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme
# List of plugins used
plugins=( git sudo zsh-256color zsh-completions zsh-syntax-highlighting
fzf fzf-tab gcloud gitignore helm tmux dirhistory last-working-dir redis-cli)
source $ZSH/oh-my-zsh.sh
# In case a command is not found, try to find the package that has it
function command_not_found_handler {
local purple='\e[1;35m' bright='\e[0;1m' green='\e[1;32m' reset='\e[0m'
printf 'zsh: command not found: %s\n' "$1"
local entries=( ${(f)"$(/usr/bin/pacman -F --machinereadable -- "/usr/bin/$1")"} )
if (( ${#entries[@]} )) ; then
printf "${bright}$1${reset} may be found in the following packages:\n"
local pkg
for entry in "${entries[@]}" ; do
local fields=( ${(0)entry} )
if [[ "$pkg" != "${fields[2]}" ]]; then
printf "${purple}%s/${bright}%s ${green}%s${reset}\n" "${fields[1]}" "${fields[2]}" "${fields[3]}"
fi
printf ' /%s\n' "${fields[4]}"
pkg="${fields[2]}"
done
fi
return 127
}
# Detect AUR wrapper
if pacman -Qi yay &>/dev/null; then
aurhelper="yay"
elif pacman -Qi paru &>/dev/null; then
aurhelper="paru"
fi
function in {
local -a inPkg=("$@")
local -a arch=()
local -a aur=()
for pkg in "${inPkg[@]}"; do
if pacman -Si "${pkg}" &>/dev/null; then
arch+=("${pkg}")
else
aur+=("${pkg}")
fi
done
if [[ ${#arch[@]} -gt 0 ]]; then
sudo pacman -S "${arch[@]}"
fi
if [[ ${#aur[@]} -gt 0 ]]; then
${aurhelper} -S "${aur[@]}"
fi
}
# 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
export EDITOR=vim
export VISUAL=vim
# Use neovim if available
if [[ -x "$(command -v nvim)" ]]; then
alias vim="nvim"
alias vi="nvim"
export EDITOR=nvim
export VISUAL=nvim
fi
export BROWSER=google-chrome-stable
# Use eza if available
if [[ -x "$(command -v eza)" ]]; then
alias ls='eza --color=always --group-directories-first'
fi
###################
# 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:"
########################
# 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
export USE_GKE_GCLOUD_AUTH_PLUGIN=True
# 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:].,!?&*%_$#^@{}[]()<>/\+'
###################
# 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 #
#############
# Open Yazi allowing cd into directory on exit.
function y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
yazi "$@" --cwd-file="$tmp"
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
builtin cd -- "$cwd"
fi
rm -f -- "$tmp"
}
# 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 [email protected]'
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
}
###########
# Aliases #
###########
alias c='clear' # clear terminal
# Directory navigation shortcuts
alias ..='cd ..'
alias ...='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'
# Always mkdir a path (this doesn't inhibit functionality to make a single dir)
alias mkdir='mkdir -p'
# 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"
# Terraform
alias tf-auth="export GOOGLE_OAUTH_ACCESS_TOKEN=\$(gcloud auth print-access-token)"
# SSH Term
alias ssh='TERM=xterm ssh'
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Display Pokemon
# pokemon-colorscripts --no-title -r 1,3,6
# Zoxide
eval "$(zoxide init zsh)"