-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzshrc.local
More file actions
339 lines (281 loc) · 7.53 KB
/
zshrc.local
File metadata and controls
339 lines (281 loc) · 7.53 KB
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
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt APPEND_HISTORY # Don't overwrite history file
setopt INC_APPEND_HISTORY # Write to history file immediately
setopt SHARE_HISTORY # Share history between all sessions
setopt EXTENDED_HISTORY # Write timestamps
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicates first
setopt HIST_IGNORE_DUPS # Don't record duplicates
setopt HIST_FIND_NO_DUPS # Don't display duplicates in search
# 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
alias k='kubectl'
alias b='brew'
# Aliases: General
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'
alias mate='zed'
alias k9='k9s'
alias kuz='kustomize'
alias calicoctl='calicoctl --allow-version-mismatch'
alias gst='git status'
alias z='zoxide'
alias diff='difft'
#alias docker='podman'
# Brew shellenv
if [[ -e "/opt/homebrew/bin/brew" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Ruby RV
if [[ -e "/opt/homebrew/bin/rv" ]]; then
eval "$(rv shell init zsh)"
fi
image-arch() {
if [[ -z "$1" ]]; then
echo "Usage: image-arch <image-name>"
return 1
fi
docker image inspect "$1" --format '{{.Os}}/{{.Architecture}}'
}
# k3s
kubeconfig-k3s() {
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
}
load-kubeconfig() {
local base="$HOME/.kube/config"
local local_cfg="$PWD/.kubeconfig"
if [[ -f "$local_cfg" ]]; then
export KUBECONFIG="$local_cfg:$base"
else
export KUBECONFIG="$base"
fi
}
# kubectl completion
if [ $commands[kubectl] ]; then
source <(kubectl completion zsh)
fi
# kpt runtime
export KPT_FN_RUNTIME=podman
# Path: k8s krew
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
# 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/
}
checkport() {
port_number="$1"
if [[ -z "$port_number" ]]; then
echo "Usage: checkport <port-number>"
return 1
fi
sudo lsof -nP -i4TCP:$port_number | grep '(LISTEN)' | awk 'BEGIN{print "Name PID Host:Port"};{print $1 " " $2 " " $9}'
}
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 -Ls "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/. zdk@ssh.blinkenshell.org:/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}"
}
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_CTRL_R_OPTS="--no-sort --exact"
[ -f ~/.zshrc.works ] && source "$HOME/.zshrc.works"
[ -f /opt/homebrew/bin/fzf ] && source <(fzf --zsh)
# SSH Agent
# export SSH_AUTH_SOCK=~/.1password/agent.sock
# Path
export PATH="$PATH:$HOME/.local/bin"
export PATH="$HOME/bin:$PATH"
export PATH="$HOME/.pyenv/shims:$PATH"
export PATH="/opt/homebrew/opt/curl/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="$HOME/go/bin:/opt/homebrew/opt/openjdk/bin:$PATH"
export PATH="$HOME/.tfenv/bin:$PATH"
export GROOVY_HOME=/opt/homebrew/opt/groovy/libexec
#if [[ "$(uname)" == "Darwin" ]]; then
# source "/opt/homebrew/opt/kube-ps1/share/kube-ps1.sh"
# PS1='$(kube_ps1)'$PS1
#fi
#. "$HOME/.deno/env"
export AWS_DEFAULT_REGION=ap-southeast-1
export KPT_FN_RUNTIME=docker
export GPG_TTY=$(tty)