-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzsh_aliases
230 lines (189 loc) · 5.2 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
# ----------------
# common
# ----------------
alias ls='eza'
alias l='ls -al'
alias la='ls -l'
alias lt='ls --tree'
alias t=lt
alias cat=bat
alias ping=prettyping
# ----------------
# hugo
# ----------------
function blogpost() {
hugo new posts/$(date -u +"%Y%m%d")-${1}
}
# ----------------
# tmux
# ----------------
alias tmux="tmux -2 -u"
alias ta="tmux attach -d -t"
alias tp='tmuxp load'
alias ta='tmux attach -t'
alias tad='tmux attach -d -t'
alias ts='tmux new-session -s'
alias tl='tmux list-sessions'
alias tksv='tmux kill-server'
alias tkss='tmux kill-session -t'
# ----------------
# vi
# ----------------
alias vi=nvim
alias vim=nvim
# ----------------
# git
# ----------------
alias gitsh="gitsh --git $(which hub)"
alias lg=lazygit
function fco() {
local tags branches target
branches=$(
git --no-pager branch --all \
--format="%(if)%(HEAD)%(then)%(else)%(if:equals=HEAD)%(refname:strip=3)%(then)%(else)%1B[0;34;1mbranch%09%1B[m%(refname:short)%(end)%(end)" \
| sed '/^$/d') || return
tags=$(
git --no-pager tag | awk '{print "\x1b[35;1mtag\x1b[m\t" $1}') || return
target=$(
(echo "$branches"; echo "$tags") |
fzf --no-hscroll --no-multi -n 2 \
--ansi --preview="git --no-pager log -150 --pretty=format:%s '..{2}'") || return
git checkout $(awk '{print $2}' <<<"$target" )
}
# ----------------
# docker
# ----------------
function dsel {
docker container ls --all | fzf --header-lines=1 --query "${1}" --multi | awk '{ print $1 }'
}
alias drrmit='docker run --rm -it'
# localhost for lazy docker people
function dopen {
# get and count all published port mappings
published=$(docker container ls | fzf --header-lines=1 --query "${1}" | awk '{print $1}' | xargs docker container port)
# choose published port; will autochoose if there's only one port; will exit if there are none
port=$(echo "${published}" | fzf --exit-0 --select-1 | grep -oE '(\d+)$')
[ -n "${port}" ] && open "http://localhost:${port}"
}
# docker shell
function dsh {
ID=$(docker container ls | fzf --header-lines=1 --query "${1}" | awk '{print $1}')
docker exec -it "${ID}" /bin/sh
}
# ----------------
# gcloud
# ----------------
alias g=gcloud
alias gcl="gcloud config list"
alias gcs="gcloud config set"
alias gccl="gcloud config configurations list"
alias gcca="gcloud config configurations activate"
# ----------------
# Kubernetes
# ----------------
# select pod and get its ID
function ksel {
kubectl get pods --all-namespaces | fzf --header-lines=1 --query "${1}" | awk '{ print $2,"--namespace " $1 }'
}
# Run shell on pod which remians to be selected
function kpsh {
keti $(ksel) -- sh
}
# Get logs off pod which remians to be selected
function kplog {
kubectl logs -f $(ksel)
}
alias kctx=kubectx
alias kx=kubectx
alias kns=kubens
alias k=kubectl
function krename {
kubectl config rename-context $(kubectl config current-context) $1
}
# ----------------
# FluxCD
# ----------------
alias flux="fluxctl --k8s-fwd-ns flux"
# ----------------
# aws
# ----------------
alias awsv=aws-vault
function awsls {
aws configure list-profiles | fzf
}
function export_aws_profile {
export AWS_PROFILE=$(awsls)
}
function awsve {
if [ -z "$AWS_PROFILE" ]
then
profile=$(awsls)
else
profile=$AWS_PROFILE
fi
aws-vault exec ${profile} -- "$@"
}
function awsvl {
if [ -z "$AWS_PROFILE" ]
then
profile=$(awsls)
else
profile=$AWS_PROFILE
fi
aws-vault login ${profile}
}
# ----------------
# terraform
# ----------------
alias tf=terraform
alias tfp="terraform plan"
alias tfpo="terraform plan -out=plan.out"
alias tfop=tfpo
alias tfa="terraform apply"
alias tfap="terraform apply plan.out"
alias tfpp="tfop && tfap"
alias tg="terragrunt"
# ----------------
# kitty
# ----------------
alias kssh=kitty +kitten ssh
alias icat='kitty +kitten icat'
alias d="kitty +kitten diff"
# ----------------
# remote
# ----------------
alias rctl=remotectl
alias r-prod="remotectl k8s shell tiger-api -lc -e production -r devops -- tiger/bin/tiger start_iex"
alias r-sandbox="remotectl k8s shell tiger-api -lc -e sandbox -r devops -- tiger/bin/tiger start_iex"
alias r-staging="remotectl k8s shell tiger-api -lc -e staging -r engineer -- tiger/bin/tiger start_iex"
alias tiger-up="mix deps.get --force && mix compile && MIX_ENV=test mix compile && mix ecto.migrate && MIX_ENV=test mix ecto.migrate"
# ----------------
# other
# ----------------
alias wetter="curl wttr.in/hamburg"
alias drops=ds
alias ag="ag --hidden"
alias tower=gittower
alias pj='npx projen'
alias dig=dog
function cdk-diff() {
if ! [ -d "cdk.out" ]; then
echo "no 'cdk.out' dir fount. Go to your apps root dir and run 'cdk synth'."
return
fi
stage=$(ls cdk.out | grep 'assembly-' | fzf)
stack=$(ls cdk.out/$stage/*.template.json | sed -E "s|cdk\.out\/${stage}\/(.+)\.template\.json|\1|" | fzf)
npx cdk diff -a cdk.out/${stage} $stack
}
function update {
brew update && brew outdated && brew upgrade && brew cleanup
brew upgrade --cask
$ZSH/tools/upgrade.sh
mise plugins update
gem update --system
gem update neovim coderay pry awesome-print byebug pry-byebug rubocop haml_lint scss_lint
# pip3 install --upgrade pynvim Pygments tmuxp
yarn global upgrade
# gcloud components update --quiet
tldr --update
}