-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliases.zsh
207 lines (180 loc) · 5.73 KB
/
aliases.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
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
# .aliases.zsh
alias edit_aliases="nvim $HOME/.aliases.zsh"
alias reload_aliases="source $HOME/.aliases.zsh"
# Git Aliases & Functions
alias g="git"
alias ga="git add"
alias gd="git diff"
alias gds="git diff --staged"
alias gmp="git_main_pull && git_cleanup_branches.sh"
alias gst="git st"
git_fetch_all() {
for repo in $(find "$HOME"/git -type d -name .git); do
git -C $(dirname "$repo") fetch --all
done
}
git_main_pull() {
main_branch_exists=$(git branch --list | grep -c -e '^[* ] main$')
if [ "$main_branch_exists" -eq 1 ]; then
default_branch=main
else
default_branch=master
fi
git checkout $default_branch
git pull origin $default_branch
}
git_remote() {
git_root=$(git rev-parse --show-toplevel)
git_repo=$(basename "$git_root")
git_user=$1
git remote add "$git_user" "git@github.com:$git_user/$git_repo.git"
}
github_query_commit() {
org=$1
repo=$2
sha=$3
curl -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/$org/$repo/commits/$sha" | jq .commit
}
github_open_commit() {
org=$1
repo=$2
sha=$3
open "https://github.com/$org/$repo/commit/$sha"
}
# Kubectl Aliases
alias k="kubectl"
alias kapply="kubectl apply -f"
alias kctx="kubectx"
alias kd="kubectl describe"
alias kdd="kubectl describe deployments"
alias kdds="kubectl describe daemonsets"
alias kdp="kubectl describe pod"
alias kds="kubectl describe services"
alias kdst="kubectl describe statefulsets"
alias kexec="kubectl exec -it"
alias kg="kubectl get"
alias kga="kubectl get all"
alias kgd="kubectl get deployments"
alias kgds="kubectl get daemonsets"
alias kge="kubectl get events --sort-by='.metadata.creationTimestamp'"
alias kgn="kubectl get nodes"
alias kgp="kubectl get pod"
alias kgs="kubectl get services"
alias kgst="kubectl get statefulsets"
alias kl="kubectl logs -f"
alias kns="kubens"
alias krm="kubectl delete"
alias krmd="kubectl delete deployment"
alias krmp="kubectl delete pod"
# Other Aliases & Functions
alias cloudshell='gcloud cloud-shell ssh'
alias d="docker"
alias pip_upgrade="pip list --local --outdated --format freeze | cut -d= -f1 | xargs pip install --upgrade"
alias spotify_track='osascript -e '\''tell application "Spotify" to artist of current track & " - " & name of current track'\'
alias tre="trans en:fr"
alias trf="trans fr:en"
alias vim=nvim
alias week_number="date +'So this is week: %U of %Y'"
alias yt=" youtube-dl"
mkcd() {
mkdir -p -- "$1" && cd -P -- "$1"
}
venv_tmp() {
packages=($@)
tmpdir=$(mktemp -d)
cd "$tmpdir"
python3 -m venv venv
./venv/bin/pip install --upgrade pip
./venv/bin/pip install --upgrade setuptools
./venv/bin/pip install --upgrade wheel
./venv/bin/pip install --upgrade ipython
for pkg in ${packages[@]}; do
./venv/bin/pip install "$pkg"
done
source ./venv/bin/activate
}
tz() {
# zones in /usr/share/zoneinfo
for zone in US/Pacific US/Central US/Eastern UTC Europe/Amsterdam Europe/Paris Australia/Adelaide; do
TZ="$zone"
echo "$TZ"
printf " "
TZ="$TZ" date
done
}
update() {
brew update && brew upgrade && brew upgrade --cask && brew cleanup
pipx upgrade-all
}
# FZF Functions
# https://mattorb.com/the-many-faces-of-fzf/
fcd() {
set -x
if [ -z "$1" ]; then
searchdir=.
else
searchdir=$1
fi
destdir=$(find "$searchdir" \( ! -regex '.*/\..*' \) ! -name __pycache__ ! -name venv ! -name .direnv -type d | fzf)
if [ -z "$destdir" ]; then
return 1
else
echo Destination: "$destdir"
cd "$destdir"
fi
}
# https://mattorb.com/the-many-faces-of-fzf/
fkill() {
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
if [ -n "$pid" ]; then
echo "$pid" | xargs kill -9
fi
}
git_browse_commits() {
git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
fzf --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \
--bind "ctrl-m:execute:
(grep -o '[a-f0-9]\{7\}' | head -1 |
xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF'
{}
FZF-EOF"
}
# https://seb.jambor.dev/posts/improving-shell-workflows-with-fzf/
git_delete_branches() {
git branch |
grep --invert-match '\*' |
cut -c 3- |
fzf --multi --preview="git log {} --" |
xargs --no-run-if-empty git branch --delete --force
}
# https://seb.jambor.dev/posts/improving-shell-workflows-with-fzf/
git_pr_checkout() {
local pr_number
pr_number=$(
gh api 'repos/:owner/:repo/pulls' |
jq --raw-output '.[] | "#\(.number) \(.title)"' |
fzf |
sed 's/^#\([0-9]\+\).*/\1/'
)
if [ -n "$pr_number" ]; then
gh pr checkout "$pr_number"
fi
}
git_clean_squash_merge_branches_master() {
git checkout -q master && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base master $branch) && [[ $(git cherry master $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done
}
git_clean_squash_merge_branches_main() {
git checkout -q main && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base main $branch) && [[ $(git cherry main $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done
}
vault_totp() {
vault read --field=code "totp/code/$(vault list totp/keys | fzf)"
}
vault_totp_copy() {
if [ "$1" = "list" ]; then
vault list totp/keys
return
fi
vault read -field=code "totp/code/$1" | pbcopy
echo "TOTP for $1 copied to clipboard"
}