-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.zsh
179 lines (146 loc) · 2.73 KB
/
utils.zsh
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
#!/bin/zsh
marks_list="${CONFIG_DIR}/marks.list"
default_marks=(
"config : ${CONFIG_DIR}"
"lab : ${HOME}/dev/lab"
"projects : ${HOME}/dev/projects"
"work : ${HOME}/dev/work"
)
start_sway() {
local current_tty="$(tty)"
if [[ "$current_tty" =~ ^/dev/tty[0-9]+$ ]]; then
if [[ "${current_tty: -1}" == "1" ]]; then
sway
fi
elif [[ -z "$SSH_CLIENT" && -z "$SSH_TTY" ]]; then
tmux source-file "${TMUX_DIR}/tmux.conf"
else
echo "foo"
fi
# if ! systemctl -q is-active libvirtd.service; then
# systemctl -q start libvirtd.service
# fi
}
generate_marks() {
dirs=`find $HOME/* -maxdepth 2 -type d`
dirs_count=$(echo $dirs | wc -l)
total_marks=$(cat $marks_list | wc -l)
marks_count=$(($total_marks - ${#default_marks}))
if [[ "$dirs_count" != "$marks_count" ]]; then
printf '%s\n' "${default_marks[@]}" >$marks_list
echo "$dirs" |
cut -d ' ' -f 2 |
xargs -I % bash -c 'echo "$(grep -Po "[^/]+/[^/]+$" <<< "%") : %"' \
>>$marks_list
fi
}
kbsel() {
kustomize build \
--enable-alpha-plugins \
--enable-exec \
$1 |
yq -o json |
jq \
-s \
--arg kind $2 \
--arg name $3 \
'map(select(.kind == $kind and .metadata.name == $name)) | first'
}
startc() {
sudo docker run \
--env-file .env \
--net host \
--init \
--rm \
-it \
$@
}
gcpnv() {
git add .
git commit -am "$1"
git push origin $(git_current_branch) --no-verify
}
psqlv() {
psql -Atc "$1" | wl-copy -n
}
mc() {
mkdir -p "$1"
cd "$1"
}
db() {
sudo docker build -t "$1" ${@:2} .
}
pmrq() {
pmr $(pmqq $@)
}
k() {
kubectl $@ --cache-dir "${CACHE_DIR}/kube"
}
kc() {
k --context "$1" ${@:2}
}
kcv() {
kc "$1" view ${@:2}
}
kcg() {
kc "$1" get ${@:2}
}
kcga() {
kc "$1" get all ${@:2}
}
kcgaa() {
kc "$1" get all --all-namespaces ${@:2}
}
kb() {
kustomize build --load-restrictor LoadRestrictionsNone $@
}
kbj() {
kb | yq -s
}
kka() {
if [[ -z "$1" ]]; then
echo "Context argument required"
return 1
fi
build() {
kb | kc "$1" apply -f - ${@:2}
}
if [[ -n "$2" ]]; then
build "$1" \
--prune \
--prune-allowlist /v1/ConfigMap \
--prune-allowlist /v1/Secret \
-n "$2" \
-l "app=${2}" \
${@:3}
else
build "$1" ${@:2}
fi
}
kkda() {
kka "$1" "$2" --dry-run=server
}
k9() {
if [[ -z "$1" ]]; then
echo "Context argument required"
return 1
fi
k9s --context "$1" -A
}
tldr() {
sudo docker run \
--rm \
-it \
-v "${CACHE_DIR}/tldr:/root/.tldr/cache" \
nutellinoit/tldr \
$@
}
mkss() {
mks --addons metallb,ingress,default-storageclass
}
ssht() {
ssh \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
$@
}