-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aliasrc
170 lines (153 loc) · 5.82 KB
/
.aliasrc
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
#!/usr/bin/env bash
# shellcheck disable=SC1090
# Make common commands shorter
# shellcheck disable=SC2142
alias \
q="exit" \
c="clear" \
e="\$EDITOR" \
g="git" \
p="paccy" \
se="sudoedit" \
sshp='ssh -o "StrictHostKeyChecking=no" -o PreferredAuthentications=password -o PubkeyAuthentication=no' \
bs='source ~/.bashrc' \
lg='lazygit' \
task='go-task' \
ch="code . && exit" \
bye='systemctl suspend-then-hibernate' \
utop='htop -t -u $(whoami)' \
perms="stat -c '%a %n' *" \
mimetype="file --dereference --brief --mime-type" \
archive="7z a -m0=LZMA2 -mx=9 -mmt\$(nproc) archive.7z" \
update="paccy -Syu" \
pf='rg --files | fzf --preview "bat --color=always --style=numbers --line-range :200 {}"' \
pf.='rg --files --hidden | fzf --preview "bat --color=always --style=numbers --line-range :200 {}"' \
ef='nvim "$(pf)"' \
ef.='nvim "$(pf.)"' \
gu='xdg-open "$(git config --get remote.origin.url)"' \
cheat='_x() { curl cht.sh/"$1"; }; _x' \
tgs='tmux-go-session' \
pnav='cd "$(_projselect)"' \
dlmv='mv ~/Downloads/"$(\ls -At ~/Downloads | head -n1)" .' \
urldecode='python3 -c "import sys, urllib.parse as ul; print(ul.unquote_plus(sys.argv[1]))"' \
urlencode='python3 -c "import sys, urllib.parse as ul; print (ul.quote_plus(sys.argv[1]))"' \
vset='_x() { read -r "$1" && export "$1"; }; _x' \
set_aws_profile='export AWS_PROFILE="$(aws configure list-profiles | fzf)"' \
unset_aws_profile='unset AWS_PROFILE'
# Helm
alias \
hls="helm ls" \
hdu="helm dependency update" \
hui="helm upgrade --install" \
hur="helm upgrade --reuse-values" \
hua='helm uninstall $(helm ls --short)'
# Kubectl
# shellcheck disable=SC2154
alias \
kgc='kubectl config current-context' \
kgn='kubectl config get-contexts --no-headers "$(kgc)" | awk "{print \$5}" | sed "s/^$/default/"' \
klc='yq ".contexts.[].name" ~/.kube/config' \
kln='kubectl get namespaces -o custom-columns=NAME:.metadata.name --no-headers' \
ksn='kubectl config set-context --current --namespace "$(kln | fzf --header "select ns. ctx: ["$(kubectl config current-context)"]")"' \
ksc='_x() { set -euo pipefail; s="$(klc | fzf)"; yq e -i ".current-context = \"$s\"" ~/.kube/config; }; (_x)' \
k='kubectl'
# kdcn='command kubectl delete ns "$(krn)"'
# kccn='command kubectl create ns "$(krn)"'
# Docker
alias \
dshell='_x() { docker run --entrypoint /bin/bash --rm -it "$1" || docker run --entrypoint /bin/sh --rm -it "$1"; }; _x' \
dprune='docker system prune -a --volumes' \
drr='docker run --rm'
# Better flags
alias \
grep="grep --color=auto" \
diff="diff --color=auto" \
ip="ip -color=auto" \
cp="cp -i" \
mv="mv -i" \
rm="rm -v" \
mkdir="mkdir -p" \
free="free -h" \
df="df --human-readable --output=source,target,size,used,avail,pcent" \
upower="upower -i /org/freedesktop/UPower/devices/battery_BAT0" \
dd="dd bs=512k status=progress" \
gcc="gcc -Wall -W -pedantic" \
htop="htop -s PERCENT_CPU" \
mpv='mpv --hwdec=auto' \
du='du --human-readable'
# Navigation
alias \
..='cd ..' \
...='cd ../..' \
....='cd ../../..' \
h='cd ~' \
bin='cd ~/dotfiles/.local/bin' \
dl='cd ~/Downloads' \
dots='cd ~/dotfiles' \
config='cd ~/dotfiles/.config'
[ -x "$(command -v bat)" ] && alias cat="bat"
if [ "$(uname -s)" = "Darwin" ]; then
alias \
ls="gls -hN --color=auto --group-directories-first" \
ll="gls -hNlA --color=auto" \
find="gfind" \
sed="gsed"
else
alias \
ls="ls -hN --color=auto --group-directories-first" \
ll="ls -hNlA --color=auto"
fi
command -v kubectl >/dev/null 2>&1 && . <(kubectl completion bash)
command -v kubectl >/dev/null 2>&1 && complete -o default -F __start_kubectl k
command -v helm >/dev/null 2>&1 && . <(helm completion "${SHELL##*/}")
command -v k6 >/dev/null 2>&1 && . <(k6 completion "${SHELL##*/}")
command -v gh >/dev/null 2>&1 && . <(gh completion -s "${SHELL##*/}")
command -v direnv >/dev/null 2>&1 && . <(direnv hook "${SHELL##*/}")
sd() {
set -e
tmp_file="$(mktemp)"
trap 'rm -rf -- "$tmp_file"' EXIT INT TERM HUP
sail -write-wd "$tmp_file"
pushd "$(cat "$tmp_file")" >/dev/null
set +e
}
# Git browse
gbrowse() {
git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
fzf --ansi --no-sort --reverse --tiebreak=index +m \
--bind "ctrl-m:execute: git show --color=always \$(echo {} | cut -d' ' -f2)" \
--preview "git show --stat --color=always \$(echo {} | cut -d' ' -f2)" \
--preview-window=right,60
}
# Switch directory
# sd() {
# local t
# t="$({ fd . --type directory -I 2>/dev/null || find . -type d -not -path '*/.*' 2>/dev/null; } | fzf-tmux -p)"
# [ -n "$t" ] && cd "$t" && ls
# }
# sdh() {
# local t
# t="$({ fd . --type directory -HIE '.git' 2>/dev/null || find . -type d -not -path '*/\.git/*' 2>/dev/null; } | fzf-tmux -p)"
# [ -n "$t" ] && cd "$t" && ls
# }
gzip_webcheck() {
set -x
curl "$1" --silent --write-out "%{size_download}\n" --output /dev/null
curl "$1" --silent -H "Accept-Encoding: gzip,deflate" --write-out "%{size_download}\n" --output /dev/null
set +x
}
_man_help() {
res="${READLINE_LINE%% *}"
help "$res" 2>/dev/null || man "$res"
}
bind -m vi-insert -x '"\eh": _arg_help'
bind -m vi-insert -x '"\eH": _man_help'
# External stuff
# shellcheck disable=SC1091
[ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ] && . "/opt/homebrew/etc/profile.d/bash_completion.sh"
[ -f "/usr/share/fzf/key-bindings.${SHELL##*/}" ] && . "/usr/share/fzf/key-bindings.${SHELL##*/}"
[ -f "/usr/share/doc/pkgfile/command-not-found.${SHELL##*/}" ] && . "/usr/share/doc/pkgfile/command-not-found.${SHELL##*/}"
# shellcheck disable=SC1091
[ -r "/usr/share/bash-completion/bash_completion" ] && . "/usr/share/bash-completion/bash_completion"
fzf_dir="$(echo /opt/homebrew/Cellar/fzf/* | tail -n 1)"
[ -f "$fzf_dir/shell/key-bindings.${SHELL##*/}" ] && . "$fzf_dir/shell/key-bindings.${SHELL##*/}"