-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzshrc.linux.local
More file actions
272 lines (231 loc) · 5.54 KB
/
zshrc.linux.local
File metadata and controls
272 lines (231 loc) · 5.54 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
export EDITOR='nvim'
export VISUAL='nvim'
export MYVIMRC=~/.vimrc
# Set up fzf key bindings and fuzzy completion
if [[ ! -f fzf ]]; then
source <(fzf --zsh)
fi
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 xcopy='xclip -selection clipboard'
alias xpaste='xclip -o -selection clipboard'
# ###########
# # 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 -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}"
}
list-block-devices() {
if [[ "$(uname)" == "Linux" ]]; then
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT | grep -E 'disk|part'
elif [[ "$(uname)" == "Darwin" ]]; then
diskutil list
else
echo "Unsupported OS: $(uname)"
return 1
fi
}
unmount-device() {
if [[ $# -ne 1 ]]; then
echo "Usage: unmount_device <device>"
return 1
fi
DEVICE=$1
case "$(uname)" in
Linux)
if ! umount "$DEVICE" 2>/dev/null; then
echo "Failed to unmount device '$DEVICE'."
return 1
fi
;;
Darwin)
if ! diskutil unmountDisk "$DEVICE" 2>/dev/null; then
echo "Failed to unmount device '$DEVICE'."
return 1
fi
;;
*)
echo "Unsupported OS: $(uname)"
return 1
;;
esac
}
burn-image() {
if [[ $# -ne 2 ]]; then
echo "Usage: burn_image <iso_image_path> <device>"
return 1
fi
IMAGE_PATH=$1
DEVICE=$2
unmount-device "$DEVICE"
if [[ ! -f $IMAGE_PATH ]]; then
echo "Image file '$IMAGE_PATH' does not exist."
return 1
fi
if [[ ! -b $DEVICE ]]; then
echo "Device '$DEVICE' is not a block device."
return 1
fi
sudo dd if="$IMAGE_PATH" of="$DEVICE" bs=4096 status=progress && sync
}