.zshrc
··6 mins
I’ve customized my zsh / terminal experience and am always trying new things.
The below contains many of the things I constantly use.
Hopefully it’s structured in a way that is easy for you to pick up,
tweak, and immediately start seeing some value!
I recently added timing output at the end, to better understand which areas are taking long and which things I may want to cut down on to save some time.
# \m/_ ... _\m/ #
start=$SECONDS
# VARIABLES / SECRETS
## replace the XYZ values below and tweak file/folder locations
## USER is used throughout for your home user dir
export USER=XYZ
## PROG is used throughout for your main programming / projects folder
export PROG=/Users/$USER/XYZ
## Unleash feature flag API in Gitlab -- first XYZ is the project number in gitlab; second XYZ is the feature flag instance id; third XYZ is for your Personal Access Token for Gitlab
export UNLEASH_URL=https://gitlab.com/api/v4/feature_flags/unleash/XYZ?instance_id=XYZ
export UNLEASH_API_TOKEN=XYZ
## Prod / Non-Prod Vault config for tokens and urls
export VAULT_TOKEN_NON_PROD=XYZ
export VAULT_TOKEN_PROD=XYZterminal
export VAULT_ADDR_NON_PROD=XYZ
export VAULT_ADDR_PROD=XYZ
## API Key to push git commit info to RescueTime for better time tracking
export RESCUETIME_API_KEY=XYZ
## Secret to enable Alfred workflow to type/send commands to the Google Assistant SDK
export GAST_SECRET=XYZ.apps.googleusercontent.com.json
# PATH
## uncomment and tweak locations
# export ANDROID_HOME=/Users/$USER/Library/Android/sdk # android location
# export GOPATH=/Users/$USER/go # main go folder with src, pkg, bin
# export GOROOT=/usr/local/opt/go/libexec # main go binary
# export LIQUIBASE_HOME=/usr/local/opt/liquibase/libexec
path=(
$path
/usr/local/bin
/usr/local/homebrew/bin # location of all homebrew installed binaries
# $PROG/__util/flutter/bin # flutter binary location
# $ANDROID_HOME/tools # main android tools
# $ANDROID_HOME/platform-tools # additional android tools
$HOME/bin
# /usr/local/homebrew/opt/node@10/bin # node version 10
# $GOROOT/bin # add normal go commands to path
# $GOPATH/bin # add go get / go install packages to path
# /Users/$USER/Library/Python/3.9/bin # python 3 location
# /usr/local/opt/helm@2/2.14.1 # helm 2 location
# $PROG/__util/google-assistant-sdk/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc # google sdk install location
# $LIQUIBASE_HOME # liquibase binary location
# /usr/local/opt/yq@3/bin # yq binary location for parsing YAML
)
path=($^path(N))
pathEnd=$SECONDS
# Path to your oh-my-zsh installation.
export ZSH="/Users/$USER/.oh-my-zsh"
# ZSH CONFIG
ZSH_THEME="muse"
# hyphen-insensitive completion (_ and - will be interchangeable).
HYPHEN_INSENSITIVE="true"
# automatically update without prompting.
DISABLE_UPDATE_PROMPT="true"
# how often to auto-update (in days).
export UPDATE_ZSH_DAYS=5
# enable command auto-correction.
ENABLE_CORRECTION="true"
# display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"
# make repo status checks faster by disabling marking untracked files under VCS as dirty.
DISABLE_UNTRACKED_FILES_DIRTY="true"
# ZSH plugins to load -- to many will slow down shell startup.
plugins=(copybuffer copyfile copypath git thefuck kubectl emoji encode64 history macos vscode web-search zsh-interactive-cd)
# disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
source $ZSH/oh-my-zsh.sh
pluginsEnd=$SECONDS
# USER CONFIG
# manually set language environment
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export JAVA_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_11_HOME=$(/usr/libexec/java_home -v11)
export JAVA_15_HOME=$(/usr/libexec/java_home -v15)
eval $(thefuck --alias)
# ALIAS
## java
alias java8="export JAVA_HOME=$JAVA_8_HOME"
alias java11="export JAVA_HOME=$JAVA_11_HOME"
alias java15="export JAVA_HOME=$JAVA_15_HOME"
## cmd
alias reload="source ~/.zshrc"
alias cls=clear
alias lll="ls -lah" # see all files in folder (even hidden ones) with human readable size
alias psl='lsof -i -P | grep LISTEN'
alias psf="ps -e | grep $1" # find process by name
alias catl="cat $1 | less" # read file
alias cpf=copyfile $1
alias cpp=copypath $1
## gcloud
alias gcssh="gcloud alpha cloud-shell ssh"
## git
alias gcmm="gcm;gl;gfa"
alias gmm="git merge master"
alias gc-="git checkout -" # go back to previous branch
alias gcamnv="gcam --no-verify"
alias ggpnv="ggp --no-verify"
## kubectl
alias kgmci="k get mci"
alias kgmcs="k get mcs"
alias kdmci="k describe mci"
alias kdmcs="k describe mcs"
alias kcrc="kubectl config rename-context"
alias kcrtc="kcrc $(kccc)"
alias kgpv="kubectl get pv"
alias kepv="kubectl edit pv"
alias kdpv="kubectl describe pv"
alias kdelpv="kubectl delete pv"
## go
alias grmg="go run main.go"
## node
### switch between node versions
alias node10='export PATH="/usr/local/opt/node@10/bin:$PATH"'
alias node15='export PATH="/usr/local/opt/node@15/bin:$PATH"'
## vault
### switch between prod / non-prod vault
alias vtnp='export VAULT_TOKEN=$VAULT_TOKEN_NON_PROD; export VAULT_ADDR=$VAULT_ADDR_NON_PROD'
alias vtp='export VAULT_TOKEN=$VAULT_TOKEN_PROD; export VAULT_ADDR=$VAULT_ADDR_PROD'
### renew vault tokens in the background
alias vtrnp='vtnp && screen -m -d $vault token renew$'
alias vtrp='vtp && screen -m -d $vault token renew$'
alias vtr='vtrnp && vtrp'
## google assistant sdk
### authenticate with google to enable alfred workflow
alias gast="google-oauthlib-tool --client-secrets $PROG/__util/google-assistant-sdk/$GAST_SECRET --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless"
### talk to your computer
alias gass="pushtotalk.py --device-model-id 'alfred' --device-id 'mbp64'"
## utils
### get your current IP address
alias getip="echo My WAN/Public IP: $(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/\"//g')"
### get password of grafana instance
alias getpass="kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo"
### show folder / file size
alias ducks="du -cksh -- * | sort -hr"
## docker
### pulsar
alias rp="docker run -it \
-p 6650:6650 \
-p 8090:8080 \
-v $PROG/data:/pulsar/data \
apachepulsar/pulsar:latest \
bin/pulsar standalone"
### jaeger
alias rj="docker run -d --name jaeger \
-e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
-p 5775:5775/udp \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 14268:14268 \
-p 14250:14250 \
-p 9411:9411 \
jaegertracing/all-in-one:1.22"
### unleash
alias ru="docker run \
-e UNLEASH_PROXY_SECRETS=unleash-proxy \
-e UNLEASH_URL='$UNLEASH_URL' \
-e UNLEASH_API_TOKEN=$UNLEASH_API_TOKEN \
-p 3000:3000 \
unleashorg/unleash-proxy"
### mongo
function rmdb {
if [ "$1" != "" ]
then
docker run --rm -it \
--name local-mongo-$1 \
-p 27017:27017 \
-v $PROG/__data/mongodb/$1:/etc/mongo \
-d mongo
else
docker run --rm -it \
--name local-mongo-local \
-p 27017:27017 \
-v $PROG/__data/mongodb/local:/etc/mongo \
-d mongo
fi
}
### postgres
alias rpg="docker run -d \
--name local-pg \
-e POSTGRES_PASSWORD=Welcome123 \
-e PGDATA=$PROG/data/postgres/pgdata \
-v $PROG/data/postgres/pgdata:/var/lib/postgresql/data \
-p 5432:5432 \
postgres"
alias pg='psql -U postgres -h localhost'
### dgraph
alias rdg="rdg0 &; rdga"
alias rdg0="docker run --rm -it \
-p 5080:5080 -p 6080:6080 -p 8080:8080 \
-p 9080:9080 -p 8000:8000 \
-v $PROG/__data/dgraph:/dgraph \
--name dgraph \
dgraph/dgraph:v21.03.0 dgraph zero"
alias rdga="docker exec -it dgraph dgraph alpha \
--cache size-mb=4096 --zero localhost:5080 --security whitelist=0.0.0.0/0"
# GLCOUD SDK
source "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc"
aliasEnd=$SECONDS
# CUSTOM FUNCS
function listening() {
if [ $# -eq 0 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P
elif [ $# -eq 1 ]; then
sudo lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color $1
else
echo "Usage: listening [pattern]"
fi
}
function maildevRunning() {
isRunning=$(lsof -i tcp:1025 | wc -l)
if [ $isRunning -eq 0 ]; then
echo "maildev is not running; starting it."
maildev &;
fi
}
function brewRefresh() {
if [[ $(date +%u) -eq 0 ]]; then echo true; else echo false; fi
}
funcDefEnd=$SECONDS
# disable strict-ssl for npm
# npm config set strict-ssl false
npmEnd=$SECONDS
# start maildev in the background
maildevRunning
maildevEnd=$SECONDS
# set default node version to 14
node14
nodeEnd=$SECONDS
# renew vault tokens
vtr
vaultEnd=$SECONDS
# source $ZSH/oh-my-zsh.sh
end=$SECONDS
echo timing:
echo "start -> path -> zsh -> plugins -> alias -> func -> npm\t-> maildev -> node -> vault -> end"
echo " $(( pathEnd - start ))s -> $(( zshEnd - pathEnd ))s -> $(( pluginsEnd - zshEnd))s -> $(( aliasEnd - pluginsEnd ))s\t -> $(( funcDefEnd - aliasEnd ))s -> $(( npmEnd - funcDefEnd ))s -> $(( maildevEnd - npmEnd ))s -> $(( nodeEnd - maildevEnd ))s -> $(( vaultEnd - nodeEnd ))s -> $(( end - vaultEnd ))s"
echo "total: $(( end - start ))s"