forked from sorin-ionescu/prezto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
429 lines (326 loc) · 11 KB
/
zshrc
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#
# Executes commands at the start of an interactive session.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
fi
# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
# Customize to your needs...
title() {
if [ $STY ]; then
echo -ne "\033 k$1\033\\"
elif [ $TMUX ]; then
if [ $# -gt 1 ]; then
tmux rename-window -t $1 $2
else
tmux rename-window $1
fi
fi
}
#PR_TITLEBAR=''
# $1 = type; 0 - both, 1 - tab, 2 - title
# rest = text
setTerminalText () {
# echo works in bash & zsh
local mode=$1 ; shift
echo -ne "\033]$mode;$@\007"
}
iterm_title () {
tab_label=${PWD/${HOME}/\~} # use 'relative' path
echo -ne "\e]2;${tab_label}\a" # set window title to full string
echo -ne "\e]1;${tab_label: -24}\a" # set tab title to rightmost 24 characters
}
stt_both () { setTerminalText 0 $@; }
stt_tab () { setTerminalText 1 $@; }
stt_title () { setTerminalText 2 $@; }
add-zsh-hook precmd stt_both
add-zsh-hook precmd stt_tab
add-zsh-hook precmd stt_title
add-zsh-hook precmd iterm_title
source ~/bin/tmuxinator.zsh
export JAVA_HOME=/usr
### Source our AWS completion fu if it's available
[ -f /usr/local/bin/aws_zsh_completer.sh ] && source /usr/local/bin/aws_zsh_completer.sh
export VIMPAGER_RC="~/.vimrc.less"
alias vless="vim -u ~/.vimrc.less"
#alias less=$PAGER
alias vless=$PAGER
alias rauns="reattach-to-user-namespace -l zsh"
alias vagrant="/opt/vagrant/bin/vagrant"
S3CMD_CONFIGFILE=$(eval $S3CMD_CONFIGFILE)
#alias s3cmd="s3cmd -c ./s3cfg"
export EDITOR='vim'
## Set GOPATH
export GOPATH=$HOME/golang
PATH=$GOPATH/bin:$PATH
### Initialize direnv, if it's installed
if [[ -x /usr/local/bin/direnv ]]; then
eval "$(direnv hook zsh)"
fi
#autoload -U tetris ; zle -N tetris ; bindkey '...' tetris
# Enable dirhistory:
# (see http://zsh.sourceforge.net/Intro/intro_6.html)
DIRSTACKSIZE=8
setopt autopushd pushdminus pushdsilent pushdtohome
alias dh='dirs -v'
### Set HOME/END keys:
bindkey "^[[1~" beginning-of-line
bindkey "^[[4~" end-of-line
# Miscellaneous
# Vagrant:
#alias vagrant-up-snap='vagrant up --no-provision && vagrant snap take'
#alias vagrant-rollback-provision='vagrant snap rollback && vagrant provision'
#alias vagrant-fuck-it='vagrant destroy -f && vagrant up'
# Vbox:
alias vbox-ls-vms='VBoxManage list vms'
alias vbox-ls-vm-state='for vm in `VBoxManage list vms | cut -d\" -f2`; do echo $vm && VBoxManage showvminfo $vm --machinereadable | grep VMState=; done'
alias vbox-shutdown-vms='for vm in `VBoxManage list vms | cut -d\" -f2`; do VBoxManage controlvm $vm savestate; done'
alias vbox-delete-vms='for vm in `VBoxManage list vms | cut -d\" -f2`; do VBoxManage unregistervm $vm --delete; done'
alias squid-purge-repodata="for url in \$(cat ~/Library/Logs/squid/squid-access.log | tail -n 100000 | grep repodata | awk '{print \$7}' | sort | uniq); do echo \$url; /usr/local/squid/bin/squidclient -m PURGE \$url; done"
alias squid-purge-all="for url in \$(cat ~/Library/Logs/squid/squid-access.log | tail -n 100000 | grep http | awk '{print \$7}' | sort | uniq); do echo \$url; /usr/local/squid/bin/squidclient -m PURGE \$url; done"
# Serves a directory via HTTP.
alias http-serve='python -m SimpleHTTPServer'
# Apt:
#alias purge-kernels="sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')"
#
# Functions
#
# Makes a directory and changes to it.
function mkdcd {
[[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1"
}
# Changes to a directory and lists its contents.
function cdls {
builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}"
}
# Pushes an entry onto the directory stack and lists its contents.
function pushdls {
builtin pushd "$argv[-1]" && ls "${(@)argv[1,-2]}"
}
# Pops an entry off the directory stack and lists its contents.
function popdls {
builtin popd "$argv[-1]" && ls "${(@)argv[1,-2]}"
}
# Prints columns 1 2 3 ... n.
function slit {
awk "{ print ${(j:,:):-\$${^@}} }"
}
# Finds files and executes a command on them.
function find-exec {
find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \;
}
# Displays user owned processes status.
function psu {
ps -U "${1:-$USER}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}"
}
# Vagrant:
function vag-up-clean-snap {
vagrant up $@ --no-provision && vagrant snap take $@
}
function vag-up-prov-snap {
vagrant up $@ --provision && vagrant snap take $@
}
function vag-rb-provision {
vagrant snap rollback $@ && vagrant provision $@
}
function vag-rb-cukes {
vagrant snap rollback $@ && vagrant cucumber
}
function vag-rb-clean {
vagrant snap rollback
}
function vag-up-cukes {
vagrant up $@ && vagrant cucumber
}
function vag-fuck-it {
vagrant destroy -f $@ && vagrant up $@
}
function vag-cuke-fuck-it {
vagrant destroy -f $@ && vagrant up $@ && vagrant cucumber
}
function vag-prov {
vagrant provision $@
}
function vag-nuke {
vagrant destroy -f $@
}
function vag-glob-nuke {
for box in $(vagrant global-status | egrep -e 'running|poweroff'| cut -d' ' -f1); do
vagrant destroy -f $box
done
}
function vag-glob-stat {
vagrant global-status
}
function vag-stat {
vagrant status $@
}
function set-current-feature-norb {
gsed -i '3i@current @norollback' $@
}
function set-current-feature-wtrb {
gsed -i '3i@current' $@
}
function del-current-feature {
gsed -i '3d' $@
}
function be {
bundle exec $@
}
function bi {
bundle install
}
function bu {
bundle update
}
function del-known-host {
sed -i -e "$1 d" $HOME/.ssh/known_hosts
}
function kill-ssh-sessions {
for ps in $(ps aux | grep \[s\]sh | awk '{ print $2 }'); do kill $ps; done
}
function git-clean-uncommitted {
for f in $(git s | grep '??' | awk '{print $2}'); do echo $f; rm -Rfv $f; done
}
function git-update-master {
git co master && git pull && git co -
}
function awsenv {
profile=$1
ak=$(cat ~/.aws/credentials|grep -A 2 $profile|grep aws_access_key|cut -d'=' -f 2 | tr -d '[:blank:]')
sk=$(cat ~/.aws/credentials|grep -A 3 $profile|grep aws_secret_access_key|cut -d '=' -f 2 | tr -d '[:blank:]')
echo
echo export AWS_ACCESS_KEY_ID=$ak
echo export AWS_SECRET_ACCESS_KEY=$sk
echo
}
# Custom SLACK update status function
function slack-status {
local SLACK_TOKEN="xxx"
local STATUS=${1:-""}
local EMOJI=${2:-"itv"}
local data='{"status_text":"'$STATUS'","status_emoji":":'$EMOJI':"}'
curl -s -o /dev/null https://slack.com/api/users.profile.set -X POST -H "Content-type: application/x-www-form-urlencoded" -d "token=${SLACK_TOKEN}&profile=$data"
}
#### GIT
checkout-pr () {
git fetch origin pull/$1/head:pr-$1 && git checkout pr-$1;
}
export DISABLE_AUTO_TITLE=true
### Stop java from creating dock icon:
export JAVA_TOOL_OPTIONS="-Dapple.awt.UIElement=true"
GPG_TTY=$(tty)
export GPG_TTY
#GPG_CONF="\$HOME/.gpg-agent-info"
#if [ -e "\$GPG_CONF" ]; then
# source "\$GPG_CONF"
# export GPG_AGENT_INFO
# export SSH_AUTH_SOCK
# export SSH_AGENT_PID
#fi
#/usr/local/MacGPG2/bin/gpg-connect-agent killagent /bye
#eval $(/usr/local/MacGPG2/bin/gpg-agent --daemon)
if [ -f ~/.gpg-agent-info ]; then
source ~/.gpg-agent-info
fi
export GPG_AGENT_INFO
export SSH_AGENT_PID
export SSH_AUTH_SOCK
gpg-connect-agent updatestartuptty /bye
#ssh -T git@github.com
#eval $(/usr/local/bin/gpg-agent --daemon)
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/andrew/bin/google-cloud-sdk/path.zsh.inc' ]; then source '/Users/andrew/bin/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/andrew/bin/google-cloud-sdk/completion.zsh.inc' ]; then source '/Users/andrew/bin/google-cloud-sdk/completion.zsh.inc'; fi
### Kube context in PROMPT:
source "${HOME}/bin/kube-ps1.sh"
PROMPT='$(kube_ps1)'$PROMPT
# get all services with in a cluster and the nodePorts they use (if any)
#alias ksvc="kubectl get --all-namespaces svc -o json | jq -r '.items[] | [.metadata.name,([.spec.ports[].nodePort | tostring ] | join(\"|\"))] | @csv'"
# shortcuts for frequent kubernetes commands
alias kc="kubectl"
compdef __start_kubectl kc
alias kpods="kubectl get po -o wide --sort-by=.status.startTime"
alias kpodsort="kubectl get po -o wide --sort-by=.status.startTime"
## alias knodes="kubectl get nodes -o wide"
alias knodes="kubectl get nodes -o wide --sort-by=\".status.conditions[?(@.reason == 'KubeletReady' )].lastTransitionTime\""
alias kget="kubectl get"
alias ktx="kubectx"
alias kns="kubens"
alias kdesc="kubectl describe"
function krun() { name=$1; shift; image=$1; shift; kubectl run -it --generator=run-pod/v1 --image $image $name -- $@; }
function klogs() { kubectl logs $*;}
function kexec(){ pod=$1; shift; kubectl exec -it $pod -- $@; }
function kpodbash(){
pod=$1
container=$2
if [ -n "${container}" ]; then
kubectl exec -it $pod -c $container -- bash
else
kubectl exec -it $pod -- bash
fi
}
function terminate-knode(){
instance=$1
kubectl drain $instance --ignore-daemonsets --delete-local-data --force
if [[ "$?" == 0 ]]; then
sleep 5
aws ec2 terminate-instances --instance-ids \
$(aws ec2 describe-instances --filters "Name=private-dns-name,Values=$instance" | jq -r '.Reservations[].Instances[].InstanceId')
else
echo "Could not drain node, not terminating"
fi
}
function hub-create-draft() {
hub pull-request --draft
}
function unset_aws_env(){
unset AWS_SECRET_ACCESS_KEY
unset AWS_ACCESS_KEY_ID
unset AWS_SESSION_TOKEN
unset AWS_SECURITY_TOKEN
unset AWS_DEFAULT_REGION
unset AWS_REGION
unset AWS_PROFILE
}
function assumeRole {
#eval $(command assume-role -duration 180m $@)
eval $(command assume-role -duration 60m $@)
aws sts get-caller-identity
aws configure list
}
export PATH="/usr/local/Cellar/gnu-getopt/2.33.2/bin":$PATH
#. /usr/local/opt/asdf/asdf.sh
#. /usr/local/opt/asdf/etc/bash_completion.d/asdf.bash
autoload -U +X bashcompinit && bashcompinit
#complete -o nospace -C /usr/local/Cellar/tfenv/2.0.0/versions/0.12.29/terraform terraform
eval "$(rtx activate zsh)"
#command -v flux >/dev/null && . <(flux completion zsh) && compdef _flux flux
# >>>> Vagrant command completion (start)
#fpath=(/opt/vagrant/embedded/gems/2.2.14/gems/vagrant-2.2.14/contrib/zsh $fpath)
#compinit
# <<<< Vagrant command completion (end)
export PATH="/Users/andrew/.local/bin":$PATH
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
alias vi="code"
alias vim="code"
export HISTSIZE=100000
source <(stern --completion=zsh)
#source <(clusterctl completion zsh)
source <(/usr/local/bin/metal completion zsh)
source <(kubectl completion zsh)
source <(rtx complete --shell zsh)
alias aws-login="aws-google-auth --bg-response js_enabled -I C03163stn -S 533705401937 -R eu-west-1 -d 28800 --resolve-aliases --username andrew.stangl@askattest.com --profile sso --ask-role"; export AWS_PROFILE=sso
KBINPATH=$(rtx where kubectl)/bin/kubectl
if [ -n "${KBINPATH}" ]; then
source <(${KBINPATH} completion zsh)
complete -o default -F __start_kubectl kc
fi