-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
300 lines (243 loc) · 6.68 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
# ZPrezto init
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
# Bindkey
bindkey '^R' history-incremental-search-backward #ok
bindkey '^[b' backward-word
bindkey '^[f' forward-word
# Editor: VIM
export EDITOR='nvim'
export VISUAL='nvim'
# RC File: VIM
export MYVIMRC=~/.vimrc
# Aliases: k8s
alias kubectl='kubecolor --kubecolor-theme=light'
alias k=kubectl
# Aliases: misc
alias tf='terraform'
alias ping='prettyping --nolegend'
alias i='/sbin/ifconfig'
alias cls='clear;ls'
alias ll='ls -la'
alias สส='ll'
alias du="ncdu --color dark -rr -x --exclude .git --exclude node_modules"
alias help='tldr'
alias mutt='LC_ALL=en_us.UTF-8 neomutt'
alias nasm='/usr/local/bin/nasm'
alias vim-noplug='vim -u NONE -U NONE --noplugin -N'
alias vim='nvim'
alias vi='vim'
alias vpn-connect='lazy-connect'
alias zel='zellij'
alias p='pulumi'
alias sed="gsed"
alias gi='git'
# k8s
# Completition
if [ $commands[kubectl] ]; then
source <(kubectl completion zsh)
fi
# krew
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
# k3s
kubeconfig-k3s() {
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
}
# Brew shellenv
if [[ -e "/opt/homebrew/bin/brew" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Path: Go
export GOPATH=$HOME/go
export PATH=$HOME/bin:$HOME/go/bin:/usr/local/go/bin:$PATH
# Path: Rust
export PATH=$HOME/.cargo/bin:$PATH
# Path: Ruby
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
# For compilers
export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/ruby/lib/pkgconfig"
# Path: Bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
# Dotnet
export DOTNET_ROOT="/opt/homebrew/opt/dotnet/libexec"
# bun completions
[ -s "$HOME/.bun/_bun" ] && source "$HOME/.bun/_bun"
# rbenv
if type rbenv > /dev/null; then
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
fi
# Path: Brew package manager
[ -f /home/linuxbrew/.linuxbrew/bin/brew ] && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
###########
# Functions
###########
encrypt() {
openssl aes-256-cbc -a -salt -in $1 -out $2
}
decrypt() {
openssl aes-256-cbc -d -a -in $1 -out $2
}
pg-backup() {
pg_dump -Z 4 -h $1 -W -U $2 $3
}
pg-restore_z() {
zcat $4 | psql -h $1 -W -U $2 $3
}
debug-http-request() {
socat - TCP-LISTEN:$1,fork
}
debug-sni-request() {
curl -k -I --resolve $1:80:$2 https://$1/
}
killport() {
while test $# -gt 0
do
port_number=$1
pid=$(lsof -P | grep ':'$port_number'[[:space:]](LISTEN)' | awk '{print $2}')
if ! kill -QUIT $pid > /dev/null 2>&1; then
echo -e "\e[0;31mNo process running\e[0m $port_number port" >&2
else
echo -e "Kill $port_number \e[0;32msuccessfully\e[0m"
fi
shift
done
}
lsport() {
sudo lsof -nP -i4TCP | grep '(LISTEN)' | awk 'BEGIN{print "Name PID Host:Port"};{print $1 " " $2 " " $9}'
}
delete-git-branch() {
git branch -D $1
git push origin --delete $1
}
checksum () {
if [[ $1 = 'md5' ]]; then
md5 $2
elif [[ $1 = 'sha1' ]]; then
shasum -a 1 $2
elif [[ $1 = 'sha256' ]]; then
shasum -a 256 $2
else
print "Unknown type: $1"
return 1
fi
}
whatismyip() {
curl -s "http://api.duckduckgo.com/?q=ip&format=json" | jq '.Answer'| grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"
}
gen-cert() {
openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out MyCertificate.crt -keyout MyKey.key
}
add-ssh-host() {
echo -en "\n\nHost $1\n HostName $2\n User $3\n IdentityFile $4" >> ~/.ssh/config
}
show-ssh-hosts() {
awk '$1 ~ /^Host$/ {print $2}' ~/.ssh/config
}
bak-now() {
cp -a "$1" "${1}_$(date "+%Y-%m-%dT%H:%M:%S%z")"
}
cpu-cores() {
sysctl -n hw.ncpu
}
cpu-generation(){
sysctl -n machdep.cpu.brand_string
}
touch-ed() {
touch $1 && vim $1
}
sync-files() {
rsync -rvz -e 'ssh -p 2222' --progress --remove-sent-files _site/. [email protected]:/home/zdk/public_html/
}
view-ssl-remote-cert() {
openssl s_client -showcerts -connect $1:443
}
join-by() {
local IFS="$1"; shift; echo "$*";
}
cdls() {
cd $1 && ls -la $1
}
cdmk() {
if [[ "$#" -ne 1 ]]; then
echo "Usage: $0 <directory>"
exit 1
fi
TARGET_DIR=$1
if [[ -d "$TARGET_DIR" ]]; then
cd $TARGET_DIR || { return 1; }
else
read "CONFIRM?Do you want to create a new directory in '$TARGET_DIR'? (yes/no): "
if [[ "$CONFIRM" == "yes" ]]; then
mkdir -p "$TARGET_DIR"
if [[ $? -eq 0 ]]; then
echo "'$TARGET_DIR' created."
cd "$TARGET_DIR" || { echo "Failed to change directory to '$TARGET_DIR'"; return 1; }
else
echo "Failed to create directory '$TARGET_DIR'"
return 1
fi
else
echo "Directory creation aborted."
fi
fi
}
nodes-ip-k8s() {
EXTERNAL_IP=$(kubectl get node $1 -o jsonpath='{.status.addresses[?(@.type=="ExternalIP")].address}');
INTERNAL_IP=$(kubectl get node $1 -o jsonpath='{.status.addresses[?(@.type=="InternalIP")].address}');
echo "External IP:" $EXTERNAL_IP;
echo "Internal IP:" $INTERNAL_IP;
}
aws-switch-profile() {
aws-profiles | grep "$1"
if [[ $? -ne 0 ]]; then
echo "profile: $1 not configured in '$HOME/.aws/config'.\n"
echo "current configured profiles:"
aws-profiles
return 1
else
export AWS_DEFAULT_PROFILE="$1" AWS_PROFILE="$1"
fi
}
aws-profiles() {
profiles=$(aws --no-cli-pager configure list-profiles 2> /dev/null)
if [[ -z "$profiles" ]]; then
echo "No AWS profiles found in '$HOME/.aws/config"
return 1
else
echo $profiles
fi
}
scan-port() {
TARGET_IP=$1
nmap -sC -sV -Pn -n -p- $TARGET_IP --open
}
k-api() {
kubectl config view --minify --output jsonpath="{.clusters[*].cluster.server}"
}
# Source files
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
[ -f ~/.zshrc.works ] && source "$HOME/.zshrc.works"
[ -f ~/.zshrc.local ] && source "$HOME/.zshrc.local"
[ -f /opt/homebrew/bin/fzf ] && source <(fzf --zsh)
export NVM_DIR="$HOME/.config/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Path: Python
export PATH="$HOME/.pyenv/shims:$PATH"
export PATH="/Users/zdk/.local/bin:$PATH"
export PATH="/opt/homebrew/opt/curl/bin:$PATH"
export PATH="$HOME/bin:$PATH"
export PATH="/opt/nvim-linux64/bin:$PATH"
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"
export PATH="$PATH:$HOME/.local/bin"
source <(kubectl completion zsh)
source "/opt/homebrew/opt/kube-ps1/share/kube-ps1.sh"
PS1='$(kube_ps1)'$PS1
. "$HOME/.deno/env"
export AWS_DEFAULT_REGION=ap-southeast-1