forked from tednaleid/shared-zshrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc_base
292 lines (221 loc) · 9.22 KB
/
zshrc_base
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
## GENERAL EXPORTS ############################################################################################################
export CLICOLOR="xterm-color"
export WORDS=/usr/share/dict/words
export HOMEBREW_NO_AUTO_UPDATE=1
# allow # on commands to be ignored
setopt INTERACTIVE_COMMENTS
setopt AUTO_CD
## GENERAL ############################################################################################################
alias dh='dirs -v' # directory history
alias is_port_open='nc -z localhost'
function wait_for_8080() {
echo "waiting for port 8080 to open up"
while ! is_port_open 8080; do sleep 0.1; done;
}
# grep history
alias gh='fc -l 0 | grep'
alias spwd='pwd | pbcopy' # copy the current working directory to the clipboard
alias pwp='pwd -P'
alias ..='cd ..'
alias ...='cd ../..'
alias cdc='cd ~/code'
# give it an url and it will see how long it takes to make 100 requests with 10 connections
alias absimple='ab -n 100 -c 10 -g gnuplot.tsv'
export VIM_EDITOR=vim
alias v='$VIM_EDITOR'
alias vz='v $ZSHDIR'
alias agrep='alias | grep -i'
# copy the last command to your clipboard
alias clc='fc -ln -1 | pbcopy && echo $(pbpaste)'
# builtins don't have their own man page
alias manbi='man zshbuiltins'
alias myip="curl icanhazip.com"
alias curltime="curl -sL -w ' namelookup: %{time_namelookup}\n connect: %{time_connect}\n appconnect: %{time_appconnect}\n pretransfer: %{time_pretransfer}\n redirect: %{time_redirect}\nstarttransfer: %{time_starttransfer}\n total: %{time_total}\n' "
alias httpcode='curl --write-out %{http_code} --head --silent --output /dev/null'
alias l='ls -lFAho'
# global aliases
alias -g 21="2>&1"
alias -g G='| grep'
alias -g GI='| grep -i'
alias -g GV='| grep -v'
alias -g GE='| egrep'
alias -g PC="| pc"
alias -g XGI="| xargs grep -ni"
alias -g XG="| xargs grep -n"
alias -g L='| less'
alias -g PBC='| pbcopy'
alias -g X1="| xargs -L1"
alias -g ND='*(/om[1])' # newest directory
alias -g NF='*(.om[1])' # newest file
alias duc='du -sh *(/)'
alias duca='du -sh ./*'
# starts a server on port 8000 that makes the current directory browsable with a webbrowser
alias webshare='python -m SimpleHTTPServer'
function server() {
local port="${1:-8000}"
open "http://localhost:${port}/"
python -m SimpleHTTPServer "$port"
}
function open_when_resolves() {
echo "Waiting for $1 to resolve and not redirect to open"
while [ ! $(curl --write-out %{http_code} --max-time 10 --silent --output /dev/null $1) = 200 ]; do printf "."; sleep 0.5; done;
open $1
}
# SSL #
alias sslserver=': SSL print out a list of the acceptable CAs for a server, as well as its public key, pass host:port; openssl s_client -prexit -showcerts -connect'
# alias sslprintcert=': SSL print out the details of a cert using keytool; keytool -v -printcert -file'
alias sslprintcert=': SSL print out the details of a cert using openssl; openssl x509 -noout -text -in'
alias sslprintprivate=': SSL print out the details of a private key using openssl; openssl rsa -noout -text -in'
## if these match, they are the public/private pair
function sslx509md5() { openssl x509 -noout -modulus -in $1 | openssl md5 }
function sslrsamd5() { openssl rsa -noout -modulus -in $1 | openssl md5 }
alias sslpublicmd5=': SSL md5 of public key, check match against private; sslx509md5 $1'
alias sslprivatemd5=': SSL md5 of private key, check match against public; sslrsamd5 $1'
alias sslpk8topem=': SSL converte pk8 private key used by java to rsa pem format private key; openssl pkcs8 -nocrypt -in'
alias sslstoredkeys=': SSL print out all of the keys in a keystore file; keytool -list -v -keystore'
alias sslstoredkeys2=': SSL print out all of the raw public keys in a keystore file; keytool -list -rfc -keystore'
alias sslcerthash=': SSL print out the hash for a certificate; openssl x509 -hash -noout -in'
## VERSION CONTROL ############################################################################################################
alias g='git'
alias gl='git pull'
alias gcam="git commit -v -am"
alias gs="git st"
alias grh="git reset --hard"
alias grs="git reset --soft"
alias gco="git checkout"
alias gd="git diff"
alias gdt="git diff"
alias gds="git diff --stat"
alias gdth1="git difftool HEAD~1"
alias gdh1="git diff HEAD~1"
alias gdtod="git difftool origin/devleop"
alias gdod="git diff origin/develop"
alias gdtom="git difftool origin/master"
alias gdom="git diff origin/master"
alias -g H1="HEAD~1"
alias -g OD="origin/develop"
alias -g OM="origin/master"
alias grom="git rebase -p origin/master"
## Java ###################################################################
function jdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $1`
export PATH=$JAVA_HOME/bin:$PATH
else
java -version
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
# jdk 1.8
#jdk 11
alias gw='nocorrect ./gradlew'
alias gwckc='if ! ktlint; then ./gradlew clean ktlintFormat check; else ./gradlew clean check; fi'
alias gwkc='if ! ktlint; then ./gradlew ktlintFormat check; else ./gradlew check; fi'
## DOCKER/KUBERNETES ######################################################
alias dc="docker compose"
#alias dc="/Users/z002vbv/Library/Python/3.9/bin/podman-compose"
# docker remove all containers
function drma () {
[[ -z $(docker ps -aq) ]] || docker rm -f $(docker ps -aq)
}
alias k="kubectl"
alias kcc="kubectl --context"
alias pods="kubectl get pods"
alias hpods="kubectl get pods -l 'team=helios'"
alias quota="kubectl describe quota compute-resources"
export EDITOR=vi
alias helios-test="kubectl config use-context helios-test-ttc"
alias helios-prod="kubectl config use-context helios-prod-ttc"
alias eic-test="kubectl config use-context item-ingestion-ttc-test"
alias eic-prod="kubectl config use-context item-ingestion-ttc-prod"
#source <(kubectl completion zsh)
function kubectl() {
if ! type __start_kubectl >/dev/null 2>&1; then
source <(command kubectl completion zsh)
fi
command kubectl "$@"
}
## Jupyter ###############################################
alias jn="jupyter notebook"
## direnv integration
eval "$(direnv hook zsh)"
show_virtual_env() {
if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
echo "($(basename $VIRTUAL_ENV))"
fi
}
PS1='$(show_virtual_env)'$PS1
## node/npm change default path ############################################
#npm set prefix ~/.npm
#PATH="$HOME/.npm/bin:$PATH"
#PATH="./node_modules/.bin:$PATH"
## Fuzzy Finder Auto Completion
FZF_SHELL="/usr/local/opt/fzf/shell"
if [[ -d "$FZF_SHELL" ]]; then
export FZF_CTRL_R_OPTS="--min-height=20 --exact --preview 'echo {}' --preview-window down:3:wrap"
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules,build}/*" 2> /dev/null'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS=$'--min-height=20 --preview \'[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file ||
(bat --style=numbers --color=always {} ||
cat {}) 2> /dev/null | head -500
\''
source "${FZF_SHELL}/completion.zsh" 2> /dev/null
source "${FZF_SHELL}/key-bindings.zsh"
alias fzfp="fzf $FZF_CTRL_T_OPTS"
alias -g F='| fzfp'
jqpath_cmd='
def path_str: [.[] | if (type == "string") then "." + . else "[" + (. | tostring) + "]" end] | add;
. as $orig |
paths(scalars) as $paths |
$paths |
. as $path |
$orig |
[($path | path_str), "\u00a0", (getpath($path) | tostring)] |
add
'
# pipe json in to use fzf to search through it for jq paths, uses a non-breaking space as an fzf column delimiter
alias jqpath="jq -rc '$jqpath_cmd' | cat <(echo $'PATH\u00a0VALUE') - | column -t -s $'\u00a0' | fzf +s -m --header-lines=1"
else
echo "missing fzf: brew install fzf ripgrep bat"
fi
bindkey '^[[A' fzf-history-widget
########## TAP
function taplogs() {
env=${2:-dev}
cluster=$1
echo "Finding instances for cluster $cluster in $env"
instance=$(tapctl list instances "$cluster" -e "$env" -o json | jq '.[0].id' -r)
echo "Found $instance"
echo "tapctl logs $instance -f --tail 10 -e $env"
tapctl logs "$instance" -f -e $"env"--tail 100 | jq .message -r
}
# e.g. tcl dccloader -e prod
alias tcl="tapctl logs --tail 10 -f --tags servergroup,instance --cluster"
####### Arduino and PlatformIO aliases
alias pmon="pio device monitor --baud 115200"
##########
set -o vi
# emacs mode doesn't appear compatible with history
# set -o emacs
########## NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
## Antibody ZSH Plugins
if command -v antibody >/dev/null 2>&1; then
source <(antibody init)
antibody bundle < "$ZSHDIR/zsh_plugins.txt"
else
echo "antibody?"
echo "brew install getantibody/tap/antibody"
fi
### Target HashiCorp Vault
export VAULT_ADDR=https://prod.vault.target.com:443
alias vault_login='vault login -method=ldap username=z002vbv'
source "/Users/z002vbv/.sdkman/bin/sdkman-init.sh"
export PATH=/usr/local/sbin:/usr/local/opt/ruby/bin:/usr/local/opt/openssl/bin:/usr/local/bin:$(go env GOPATH)/bin:/Users/z002vbv/.platformio/penv/bin:/Users/z002vbv/code/toolshed/bin:$PATH