forked from maximbaz/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zsh-aliases
369 lines (322 loc) · 11.4 KB
/
.zsh-aliases
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/usr/bin/env zsh
## generic
command -v curlie &> /dev/null && alias curl='curlie'
command -v pydf &> /dev/null && alias df='pydf'
command -v git &> /dev/null && alias diff='git diff --no-index'
command -v rmtrash &> /dev/null && alias rm='rmtrash -rf'
command -v bat &> /dev/null && alias c='bat -p' || alias c='cat'
command -v fd &> /dev/null && alias fd='fd --hidden --follow' || alias fd='find . -name'
command -v rg &> /dev/null && alias rg='rg --hidden --follow --smart-case 2>/dev/null' || alias rg='grep --color=auto --exclude-dir=.git -R'
command -v exa &> /dev/null && alias ls='exa --group --git --group-directories-first' || alias ls='ls --color=auto --group-directories-first -h'
command -v exa &> /dev/null && alias la='ll -a' || alias la='ll -A'
command -v exa &> /dev/null && alias lk='ll -s=size' || alias lk='ll -r --sort=size'
command -v exa &> /dev/null && alias lm='ll -s=modified' || alias lm='ll -r --sort=time'
alias sshprox="ssh -D 9876 -f -C -q -N"
alias e="$EDITOR"
alias d='dig +nocmd +multiline +noall +answer'
alias cp='cp -r --reflink=auto'
alias mkdir='mkdir -p'
alias hexdump='od -A x -t x1z -v'
alias http-serve='python -m http.server'
alias htpasswd='openssl passwd -apr1'
alias ip='ip -color -brief'
alias locate='locate -i'
alias o='xdg-open'
alias rm!='\rm -rf'
alias rsync='rsync --verbose --archive --info=progress2 --human-readable --partial'
alias sudo='sudo -E '
alias tree='tree -a -I .git --dirsfirst'
alias ll='ls -l'
alias utc='env TZ=UTC date'
alias gpg-change-card='gpg-connect-agent "scd serialno" "learn --force" /bye'
alias send="croc send"
alias tmux='tmux -f $HOME/.config/tmux/tmux.conf'
function md() { [[ $# == 1 ]] && mkdir -p -- "$1" && cd -- "$1" }
compdef _directories md
e64() { [[ $# == 1 ]] && base64 -w0 <<<"$1" || base64 -w0 }
d64() { [[ $# == 1 ]] && base64 --decode <<<"$1" || base64 --decode }
p() { ping "${1:-1.1.1.1}" }
tmpd() { cd "$(mktemp -d -t "${1:-tmp}.XXXXXXXXXX")" }
## networking
alias pr='ping `netstat -nr| grep -m 1 -iE ‘default|0.0.0.0’ | awk ‘{print $2}’`'
## kubectl
alias k='kubectl'
alias kc='kubectx "$(kubectx | fzf --height=10%)"'
alias kn='kubens "$(kubens | fzf --height=10%)"'
alias kd='k describe'
alias kd!='kd --all-namespaces'
alias kdp='kd pod'
alias kdel='k delete'
alias ke='k exec -ti'
alias kg='k get'
alias kg!='kg --all-namespaces'
alias kgd='kg deployment'
alias kgd!='kgd --all-namespaces'
alias kgp='kg pod'
alias kgp!='kgp --all-namespaces'
alias kgs='kg service'
alias kgs!='kgs --all-namespaces'
alias kl='kubectl logs -f'
kout() {
while IFS= read -rd: config; do
[ -f "$config" ] || continue
sed -i -E '/^\s*(access-token|expires-in|expires-on|refresh-token)/d' "$config"
done <<< "${KUBECONFIG:-$HOME/.kube/config}:"
}
## docker-compose
alias dc='docker-compose'
alias dcu='dc up -d'
alias dcd='dc down'
alias dcr='dcd; dcu'
alias dcp='dc pull'
alias dcl='dc logs -f --tail=1000'
alias dce='dc exec'
alias dcs='dc ps'
## systemctl
alias sys='systemctl'
alias sysu='systemctl --user'
alias status='sys status'
alias statusu='sysu status'
alias start='sys start'
alias startu='sysu start'
alias stop='sys stop'
alias stopu='sysu stop'
alias restart='sys restart'
alias restartu='sysu restart'
alias enable='sys enable'
alias enableu='sysu enable'
alias disable='sys disable'
alias disableu='sysu disable'
alias reload='sys daemon-reload'
alias reloadu='sysu daemon-reload'
alias timers='sys list-timers'
alias timersu='sysu list-timers'
## git
alias g='git'
alias ga='git add'
alias gaa='git add --all'
alias gap='git add -p'
alias gb='git branch'
alias gba='git branch --all'
alias gbd='git branch -D'
alias gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
alias gbo='git branch --set-upstream-to=origin/$(git symbolic-ref --short HEAD) $(git symbolic-ref --short HEAD)'
alias gbu='git branch --set-upstream-to=upstream/$(git symbolic-ref --short HEAD) $(git symbolic-ref --short HEAD)'
alias gbsb='git bisect bad'
alias gbsg='git bisect good'
alias gbsr='git bisect reset'
alias gbss='git bisect start'
alias gc='git commit -v'
alias gc!='git commit -v --amend'
alias gcn!='git commit --no-edit --amend'
alias gac='git add --all && git commit -v'
alias gac!='git add --all && git commit -v --amend'
alias gacn!='git add --all && git commit --amend --no-edit'
alias gacm='git add --all && git commit -m'
alias gcm='git commit -m'
alias gcf='git commit --fixup'
alias gcfh='git commit --fixup HEAD'
alias gacf='git add --all && git commit --fixup'
alias gacfh='git add --all && git commit --fixup HEAD'
alias gco='git checkout'
alias gcom='git checkout master'
alias gcob='git checkout -b'
alias gcop='git checkout -p'
alias gcp='git cherry-pick'
alias gcpa='git cherry-pick --abort'
alias gcpc='git cherry-pick --continue'
alias gd='git diff'
alias gds='git diff --cached'
alias gd!='git difftool -d'
alias gds!='git difftool -d --cached'
alias gf='git fetch --tags'
alias gl='git pull --tags -f --rebase --autostash'
alias glog="git log --graph --pretty='%Cred%h%Creset%C(yellow)%d%Creset %s %Cgreen(%cr) %C(blue)<%an>%Creset' --abbrev-commit"
alias gloga="git log --graph --pretty='%Cred%h%Creset%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all"
alias glogp='git log -p'
alias gm='git merge'
alias gma='git merge --abort'
alias gp='git push -u'
alias gpf='git push --force-with-lease'
alias gpf!='git push --force'
alias gra='git remote add'
alias grr='git remote remove'
alias grv='git remote -v'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias grbi='git rebase -i'
alias grbm='git rebase -i master'
alias grbom='git rebase -i origin/master'
alias gr='git reset'
alias gr!='git reset --hard'
alias grh='git reset HEAD'
alias grh!='git reset --hard HEAD'
alias garh!='git add --all && git reset --hard HEAD'
alias gs='git show --show-signature'
alias gss='git status -sb'
alias gst='git status'
alias gsa='git submodule add'
alias gsu='git submodule update --remote'
alias gsr='git submodule-remove'
gcl() {
git clone --recursive "$@"
cd -- "${${${@: -1}##*/}%*.git}"
}
grf() {
upstream="$(git remote get-url upstream 2>/dev/null || git remote get-url origin)"
if [[ $# == 1 ]]; then
if [[ "$upstream" == https* ]]; then
fork=$(echo "$upstream" | awk -v name="$1" -F/ '{ print $1 "/" $2 "/" $3 "/" name "/" $5 }')
else
fork=$(echo "$upstream" | awk -v name="$1" -F/ '{ print "https://github.com/" name "/" $2 }')
fi
git remote remove "$1" 2>/dev/null
git remote add "$1" "$fork"
git fetch "$1"
else
myfork=$(echo "$upstream" | awk -v name="$USER" -F/ '{ print "[email protected]:" name "/" $5 }')
git remote remove upstream 2>/dev/null
git remote remove origin 2>/dev/null
git remote add upstream "$upstream"
git remote add origin "$myfork"
git fetch upstream
git fetch origin
git branch --set-upstream-to=upstream/master master
fi
}
### pacman
alias paci='SNAP_PAC_SKIP=true pac -Sy'
alias paci!='pac -Sy -dd'
alias pacr='SNAP_PAC_SKIP=true pac -Rs'
alias pacr!='pac -Rs -dd'
alias pacf='SNAP_PAC_SKIP=true pac -U'
alias pacF='pacman -F'
alias pacq='pacman -Si'
alias pacl='pacman -Ql'
alias pacdiff='sudo \pacdiff; refresh-waybar-updates'
pac() {
sudo -E pacman "$@" || return 1
is_removal=0
while [[ "$1" == -* ]]; do
[[ "$1" == "-R"* ]] && is_removal=1
shift
done
if (( is_removal )); then
echo "\nCleaning up AUR repo..."
repo-remove -s /var/cache/pacman/n1ete-local/n1ete-local.db.tar "$@"
fi
echo "\nCleaning up repo cache..."
sudo -E paccache -vr -c /var/cache/pacman/pkg -c /var/cache/pacman/n1ete-local
sudo -E paccache -vruk0 -c /var/cache/pacman/pkg -c /var/cache/pacman/n1ete-local
refresh-waybar-updates
rehash
}
command -v pacman &> /dev/null && compdef pac=pacman
pacs() {
[ $# -lt 1 ] && { >&2 echo "No search term provided"; return 1; }
sudo -E pacman -Sy
tmp=$(mktemp -d)
{
NO_COLOR=true aur search -n -k NumVotes "$@"
pacman -Ss "$@"
} |
while read -r pkg; do
read -r desc
name="${pkg%% *}"
mkdir -p "$tmp/${name%/*}"
echo "$pkg" >>$tmp/pkgs
echo "$desc" >$tmp/$name
done
[ -s $tmp/pkgs ] || { >&2 echo "No packages found"; rm -rf "$tmp"; return 2; }
aur_pkgs=()
repo_pkgs=()
cat $tmp/pkgs | fzf --tac --preview-window=wrap --preview="cat $tmp/{1}; echo; echo; pacman -Si \$(basename {1}) 2>/dev/null; true" |
while read -r pkg; do
title="${pkg%% *}"
if [ "${title%/*}" = "aur" ]; then
aur_pkgs+=("${title#*/}")
else
repo_pkgs+=("${title#*/}")
fi
done
rm -rf "$tmp"
if (( ${#aur_pkgs[@]} )); then
aur sync -Sc "${aur_pkgs[@]}"
post_aur
fi
SNAP_PAC_SKIP=true pac -Sy "${aur_pkgs[@]}" "${repo_pkgs[@]}"
}
pacu() {
xargs -a <(aur vercmp-devel | cut -d: -f1) aur sync -Scu --rebuild "$@"
post_aur
pac -Syu
}
pacQ() {
[[ $# == 1 ]] || return 1;
[ -e "$1" ] && file="$1" || file="$(which "$1")"
[ -e "$file" ] || { echo >&2 "File '$1' not found, aborting."; return 1; }
pacman -Qo "$file"
}
aurs() {
aur sync -Sc "$@"
sudo -E pacman -Sy
refresh-waybar-updates
post_aur
}
alias aurs!='aurs --nover-argv -f'
aurb() {
aur build -Scf --pkgver "$@"
sudo -E pacman -Sy
refresh-waybar-updates
post_aur
}
post_aur() {
find ~/.cache/aurutils/sync -name .git -execdir git clean -fx \; >/dev/null
find /var/cache/pacman/n1ete-local -group root -delete >/dev/null
}
refresh-waybar-updates() {
systemctl --user start waybar-updates.service
}
# Switch to different dz environments, requires bash, jq, shuf and dz
vdz() {
DZ_ENV=${1}
DZ_ENV_FILE=~/.dz/env.json
if [[ ! -f ${DZ_ENV_FILE} ]]; then
echo "Missing ${DZ_ENV_FILE}"
return 1
fi
# Print environments
if [[ ! -n ${DZ_ENV} ]]; then
echo "Usage: vdz [--deactivate|environment]"
echo
echo "Available environments:"
jq -r ".environments | keys[]" ${DZ_ENV_FILE} | while read env; do
echo " ${env}"
done
echo
echo "Options:"
echo " --deactivate"
return 2
fi
# Unset all env variables we use
if [[ ${DZ_ENV} =~ "deactivate" ]]; then
echo "Unset your current deploy-zone environment"
unset DZ_BUILD_HOST DZ_BUILD_TEMPLATE DZ_BUILD_PUBLISH_URL DZ_BUILD_MIN_PLATFORM DZ_VIRTUALENV
return 0
fi
# Create DZ_BUILD_HOST
DZ_BUILD_HOST=$(jq -r ".build_hosts[]" ${DZ_ENV_FILE} | shuffle)
# Get ENV information
if [[ $(jq ".environments.${DZ_ENV}" ${DZ_ENV_FILE}) == "null" ]]; then
echo "Missing environment \"${DZ_ENV}\", check your ${DZ_ENV_FILE}"
return 3
fi
DZ_BUILD_TEMPLATE=$(jq -r ".environments.${DZ_ENV}.template_file" ${DZ_ENV_FILE})
DZ_BUILD_PUBLISH_URL=$(jq -r ".environments.${DZ_ENV}.publish_url" ${DZ_ENV_FILE})
DZ_BUILD_MIN_PLATFORM=$(jq -r ".environments.${DZ_ENV}.min_platform" ${DZ_ENV_FILE})
# Use existing virtual environment variable
DZ_VIRTUALENV=${DZ_ENV}
# Export the Information
export DZ_BUILD_HOST DZ_BUILD_TEMPLATE DZ_BUILD_PUBLISH_URL DZ_BUILD_MIN_PLATFORM DZ_VIRTUALENV
echo "Switching to deploy-zone environment: ${DZ_ENV}"
}