Skip to content

Instantly share code, notes, and snippets.

@mcascone
Last active August 6, 2024 14:22
Show Gist options
  • Save mcascone/4861119dd4fcc3a0199d388ccca09367 to your computer and use it in GitHub Desktop.
Save mcascone/4861119dd4fcc3a0199d388ccca09367 to your computer and use it in GitHub Desktop.
my zsh aliases
#!/bin/bash
# spell:disable
# setopt interactive_comments
# shellcheck disable=SC2086,1090
# this file is sourced by ~/.zshrc every time a new shell is opened
# downstairs computer
export maxc='[email protected]'
# pull in keys/tokens/etc
source ~/.secrets
## MISC
alias py="python3"
alias p=py
alias g="grep"
alias tree="tree -alF -I .git --filesfirst"
alias ..='cd ../'
alias edp='code ~/.bashrc ~/.alias ~/.funcs ~/.secrets'
alias edz='code ~/.zshrc'
alias eda='code ~/.alias'
alias edf='code ~/.funcs'
alias edb='code ~/.bashrc'
alias edsec='code ~/.secrets'
alias relp="source ~/.zshrc"
alias path='echo "$PATH" | tr ":" "\n"'
alias cdu='cd .. && echo "---> $(pwd)" && ls'
alias cdd=cdu
alias hist=history
# mkdir and cd into it
function md() {
mkdir -p "$1" && cd "$1" && echo "---> $(pwd)" && ls || return
}
# hey, i'm on a mac!
alias finder="open -a finder"
alias pbc=pbcopy
alias pbp=pbpaste
## Starship prompt
alias st=starship
alias stt='st toggle'
alias sttg='stt gcloud'
alias sttk='stt kubernetes'
### GCLOUD
alias gc=gcloud
alias gci="gc init"
alias gccl='gc container clusters list'
alias gcc='gc container'
alias show-creds='
echo "Using $CREDS_NAME AWS credentials"
echo "AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION"
echo "AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID"
echo "AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY"
echo "GCP_PROJECT_ID: $GCP_PROJECT_ID"
echo "GOOGLE_CREDENTIALS_PATH: $GOOGLE_CREDENTIALS_PATH"
'
# -A Include directory entries whose names begin with a dot (‘.’) except for . and ..
# -h When used with the -l option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte,
# Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 2 for sizes.
# -o List in long format, but omit the group id.
# -p Write a slash (‘/’) after each filename if that file is a directory.
alias ll='ls -algp'
alias la='ls -A -hop'
alias ls='ls -Gp'
alias rmd='rm -rf'
alias code='open -a "visual studio code"'
alias cl='clear'
# alias gh='cd ~/Bitovi/github && ls'
alias bgh='cd ~/Bitovi/github && ls'
# export gh=~/Bitovi/github
export bgh=~/Bitovi/github
alias mgh='cd ~/github && ls'
alias gbh="cd $BITOVI_HOME && ls"
alias vgh='cd ~/Bitovi/github/verizon && ls'
export vgh=~/Bitovi/github/verizon
## fat-finger corrections
alias owd=pwd
alias ks=ls
alias sl=ls
## GIT
alias open_remote="git remote -v | grep -m 1 origin | sed -e 's/origin//' -e 's/(fetch)//' -e 's/\.git//' | xargs open"
alias or=open_remote
alias gr='git remote -v | grep -m 1 origin | sed s/origin\s*// | sed s/\(fetch\)// | tr -d [:blank:] | tee >(pbcopy)'
alias com='git checkout main 2>/dev/null || git checkout master'
alias cod='git checkout develop'
alias gitc='git clone'
alias gitf='git fetch -p'
alias gp='git pull'
alias gitb='git branch'
alias newbranch='git co -b'
alias newb=newbranch
alias gupdate='git fetch -p && git pull'
alias gup=gupdate
## GH CLI, ACT
alias act='gh act --container-architecture=linux/amd64 -s GITHUB_TOKEN="$(gh auth token)"'
## TERRAFORM
alias tf=terraform
alias tfa='tf apply -auto-approve'
alias tfp='tf plan'
alias tfd='tf destroy -auto-approve'
alias tfo='tf output'
alias tfs='tf state pull'
alias tfi='tf init'
alias tfir='tf init -reconfigure'
alias tfv='tf validate'
alias tff='tf fmt'
alias tfr='tf refresh'
alias pl=pluralith
## BREW
alias b=brew
alias boutdated='b outdated'
alias bout=boutdated
alias bup='b upgrade'
alias bupgrade=bup
alias bupdate='b update'
alias binst='b install'
alias bins=binst
alias binstall=binst
alias buninst='b uninstall'
alias bun=buninst
alias brm='b uninstall'
alias blist='b list'
alias bls=blist
alias bsvc='b services'
alias bs='b search'
## NODE / NPM
NODE_VERSION=$(ls ~/.nvm/versions/node | sed 's/\/$//')
export PATH="$HOME/.nvm/versions/node/$NODE_VERSION/bin:$PATH"
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
##### K8s
## get cluster .kubeconfig info (server, certs, etc)
## add --context=<context-name> to use a specific context
# alias k='kubectl 2>/dev/null'
alias k='kubectl'
alias kc='k config'
alias kgetcontextdata='k config view --minify --flatten'
alias kgetkubeconfig=kgetcontextdata
alias ksetns='k config set-context --current --namespace'
# alias kgetns='k config view --minify | grep namespace'
alias kgetns="k config view --minify | yq '.contexts[].context.namespace'"
alias kcgc='k config get-contexts'
alias kcuc='kc use-context'
alias kgpoa='k get po -A'
alias kaf='k apply -f'
alias kdf='k delete -f'
# So that you can use `kubectl run pod-name -n namespace $do > pod.yaml` or with `kubectl create` commands.
export do="-o yaml --dry-run=client"
# run 'k9s $ro' for safety
export ro=--readonly
alias mk=minikube
alias mks='mk status'
alias m8='microk8s'
alias m8s='m8 status'
alias eks=eksctl
alias ek=eksctl
alias openlens='open -a openlens'
### DOCKER
# required for images built on mac M1 to work externally
# frequently need to *unset* for remote images to work correctly
alias set-docker-platform='DOCKER_DEFAULT_PLATFORM=linux/amd64'
alias sdp=set-docker-platform
alias unset-docker-platform='unset DOCKER_DEFAULT_PLATFORM'
alias udp=unset-docker-platform
# to use as $ca in docker commands
export ca='--container-architecture=linux/amd64'
# use as $ep in docker commands
export ep='--entrypoint /bin/bash'
alias d=docker
alias dls='d images'
alias dps='d ps'
alias dpsa='d ps -a'
alias dpsaq='d ps -aq'
alias drm='d image rm'
alias dr='d run --rm -it'
alias db='d build .'
alias dbt='d build . -t'
# docker compose
alias dc='d compose'
alias dcu='dc up -d'
alias dcd=dcu
alias dcps='dc ps'
alias dcpsa='dc ps -a'
# starts docker daemon and docker desktop
alias od='open -a docker'
alias dv='d volume'
alias dvls='dv ls'
alias dn='d network'
alias dlogs='d logs --follow'
function shell() {
if [ -z "$1" ]
then
echo "Please provide a container name"
return
fi
docker exec -it $1 /bin/bash
}
### COLIMA
# alias col=colima
# alias cols='col start'
##### HELM
alias h=helm
alias hl='h list'
alias hla='h list -A'
alias hinst='h upgrade --install'
alias hinstall=hinst
alias tg=terragrunt
## example of doing a template for commercestoreservice while using the staging values yaml
# helm dep up && helm template --debug commercestoreservice . -f ~/workspaces/Yum/operations-prod/staging/helm/commercestoreservice/values.yaml | yh
alias gk='echo $KUBECONFIG'
# alias get-bitops-config="echo BITOPS_ENV_NAME: $BITOPS_ENV_NAME && echo OPS_REPO_PATH: $OPS_REPO_PATH"
alias show='typeset -f'
alias get-command=show
alias dcb='dc build'
alias act='act $ca'
alias dkb='docker kill bitops 2>/dev/null ; docker rm bitops 2>/dev/null'
# _________
# < VERIZON >
# ---------
# \ ^__^
# \ (oo)\_______
# (__)\ )\/\
# ||----w |
# || ||
# [ WELKTX08LAB-Automation-MongoDB-01]="10.139.225.59"
# ["WELKTX08LAB-Automation-MongoDB-02"]='10.139.225.60'
# ["WELKTX08LAB-Automation-MongoDB-03"]='10.139.225.61'
# ["WELKTX08LAB-Automation-OpsManager-01"]='10.139.225.62'
# ["WELKTX08LAB-Automation-OpsManager-02"]='10.139.225.63'
# ["WELKTX08LAB-Automation-OpsManager-03"]='10.139.225.64'
# export VERIZON_USER="cascoma"
# export mongoDB01="[email protected]"
# export mongoDB02="[email protected]"
# export mongoDB03="[email protected]"
# export OpsManager01="[email protected]"
# export OpsManager02="[email protected]"
# export OpsManager03="[email protected]"
# export stdev="[email protected]" # welktx08lab-stackstorm-dev.vzwnet.com
# export stprod="[email protected]" # welktx08lab-stackstorm.vzwnet.com
# export vzprom="[email protected]" # WELKTX08LAB-prometheus
# export newjenks="[email protected]" # WELKTX08LAB-jenkins-ma-01
# export oldjenks="[email protected]" # welktx08lab-prometheus.vzwnet.com
# export WELKTX08LAB-MongoDB-Dev-01="10.139.225.123"
# export WELKTX08LAB-MongoDB-Dev-02="10.139.225.124"
# export WELKTX08LAB-MongoDB-Dev-03="10.139.225.125"
alias sp='sshpass -e ssh' # use as `sp $mongoDB01` or `sp $OpsManager01` etc. Requires SSHPASS set in env
# export erakey="$vgh/era/era"
# export st2key=/Users/maximiliancascone/.ssh/verizon/st2db
# export masterkey=/Users/maximiliancascone/Bitovi/github/verizon/masterkey/masterkey
function _sshHelper() {
if [ -z "$1" ]
then
echo "Please provide a host"
return
fi
echo $(echo "$1" | tr -d "[:blank:]")
}
# function sshe() {
# host=$(_sshHelper "$@")
# ssh -i $erakey era@$host
# }
# function sshm() {
# host=$(_sshHelper "$@")
# ssh -i $masterkey jenkins_service@$host
# }
function sshu() {
host=$(_sshHelper "$@")
ssh ubuntu@$host
}
alias sshr='ssh-keygen -R'
# export mongoun=mctelab
# mongodb://mtcelab:uTxqk5rNkEUKYJdgmJVd@welktx08lab-automation-mongodb-01:27017,welktx08lab-automation-mongodb-02:27017,welktx08lab-automation-mongodb-03:27017/admin?authSource=admin&replicaSet=replSet&ssl=false&readPreference=primaryPreferred
alias a=ansible
alias ap=ansible-playbook
alias ag=ansible-galaxy
alias agi='ansible-galaxy install -f -r'
alias av=ansible-vault
alias ad='ansible-vault decrypt'
alias ae='ansible-vault encrypt'
# alias ansible-setup='a all -m setup -i st2-inventory --key-file $st2key --vault-password-file vault_password -u root'
# export vpf='--vault-password-file vault_password'
# export ekf='--key-file $erakey'
########## Nutanix Calm ##########
# function deleteCalmVm() {
# if [ -n "$1" ]; then
# curl --request DELETE \
# --url https://10.139.226.12:9440/api/nutanix/v3/apps/$1 \
# --insecure \
# --header 'Authorization: Basic Y2FzY29tYTpNRTI+Vm50bnhwYw==' \
# --header 'Content-Type: application/json' \
# --data '{}'
# else
# echo "need a target!"
# fi
# }
#!/bin/bash
# spell:disable
# shellcheck disable=1091,2086,1090
# # use: <some command> 2>$null
# export null=/dev/null
# # set aliases
source ~/.alias # also sources ~/.secrets
source ~/.funcs
# # init_helm_repo_config # run the helm repo init
# # prep_yum
# export BITOVI_HOME="$HOME/Bitovi"
# export BITOPS_HOME="$BITOVI_HOME/bitops"
# # Homebrew
# export HOMEBREW_NO_ENV_HINTS=1
# ### Docker on M1
# export DOCKER_DEFAULT_PLATFORM=linux/amd64
# # GCP
# # export GOOGLE_APPLICATION_CREDENTIALS=~/.gcp/parabolic-eon-374320-09a90c606093.json # personal
# export GOOGLE_APPLICATION_CREDENTIALS=~/.gcp/bitovi-devops-9ce00048228f.json # bitovi acct
# export GOOGLE_CREDENTIALS_PATH=$GOOGLE_APPLICATION_CREDENTIALS
# export TF_VAR_GOOGLE_CREDENTIALS_PATH=$GOOGLE_CREDENTIALS_PATH
# export GCP_PROJECT_ID=296098790459
# export TF_VAR_GCP_PROJECT_ID=$GCP_PROJECT_ID
# export GCP_DEFAULT_REGION=us-central
# export TF_VAR_GCP_DEFAULT_REGION=$GCP_DEFAULT_REGION
# export GCP_DEFAULT_ZONE=us-central-1a
# export TF_VAR_GCP_DEFAULT_ZONE=$GCP_DEFAULT_ZONE
# # enable case-insensitive autocompletion
# bind 'set completion-ignore-case on'
# zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
# autocompletions
# these have to be after the autoload line
# source <(kubectl completion bash)
# source <(helm completion bash)
# source /opt/homebrew/etc/bash_completion.d/az
# source ~/google-cloud-sdk/completion.zsh.inc
# source ~/google-cloud-sdk/path.zsh.inc # updates PATH for the Google Cloud SDK.
# terraform -install-autocomplete
# complete -o nospace -C /opt/homebrew/bin/terraform terraform
# source <(pluralith completion bash)
# turn on Starship
eval "$(starship init bash)"
# don't print '%' or '#' at EOL when there is no newline
# i think this is zsh-specific, other shells have similar options
# PROMPT_EOL_MARK=
# ## YUM settings
# export YUM_CODE_DIR=~/yum/github
# export YUM_CODE_PATH=$YUM_CODE_DIR
# export PATH=${PATH}:$YUM_CODE_DIR/yumsre-infraops/kubectl-plugins
# export PATH=${PATH}:$YUM_CODE_DIR/yumsre-infraops/yum-sre-utils/bin
# export YUM_DIFFTYPE=icdiff
# export YUM_CONTAINER_CLI=docker
# export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
eval "$(gh copilot alias -- bash)"
#!/bin/zsh
# shellcheck disable=SC1071
# setopt interactive_comments # allows comments inline without breaking funcs
######
###### BitOps
######
# function deploy_bitops() {
# echo Running BitOps Deploy...
# if [ -z "$BITOPS_ENV_NAME" ]; then
# echo -e 'You need to set BITOPS_ENV_NAME\nExiting.'
# elif [ -z "$OPS_REPO_PATH" ]; then
# echo -e 'You need to set OPS_REPO_PATH\nExiting.'
# else
# echo BITOPS_ENV_NAME: $BITOPS_ENV_NAME
# echo OPS_REPO_PATH: $OPS_REPO_PATH
# docker run --rm --name bitops \
# -e BITOPS_ENVIRONMENT=$BITOPS_ENV_NAME \
# -e GCP_SECRET_ACCESS_KEY=$GCP_SECRET_ACCESS_KEY \
# -e BITOPS_LOGGING_LEVEL=DEBUG \
# # -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION \
# # -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
# # -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
# -v $OPS_REPO_PATH:/opt/bitops_deployment \
# -v /opt/bitops/scripts/installed_plugins/gcp \
# bitovi/bitops-gcp-dev:latest
# fi
# }
### pseudo-environments
function prep_bitovi() {
export CREDS_NAME=Bitovi
echo "Setting $CREDS_NAME credentials and env vars."
export AWS_DEFAULT_REGION=ca-central-1
export AWS_ACCESS_KEY_ID=$BITOVI_AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$BITOVI_AWS_SECRET_ACCESS_KEY
}
alias prep-bitovi=prep_bitovi
function alphabet_rand() {
node -e "\
const { randomBytes } = require('crypto'); \
function rand(length, alphabet) { \
return new Promise((resolve, reject) => { \
let result = ''; \
randomBytes(length, (err, buff) => { \
if (err) { \
reject(err); \
} else { \
const alen = alphabet.length; \
for (let i = 0; i < length; i++) { \
result += alphabet[buff[i] % alen]; \
} \
resolve(result); \
} \
}); \
}); \
} \
rand($1, '$2').then(console.log).catch((err) => { \
console.error(err); \
process.exit(1); \
});"
}
alias alphabet-rand-gen-32-alphanum='alphabet_rand 32 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 | tee /dev/tty | pbcopy'
alias gen-rand-alpha=alphabet-rand-gen-32-alphanum
function action_validator() {
local filepath=$1
npx action-validator $filepath && echo 'Looks Good To Me!'
}
alias avalidator=action_validator
alias aval=avalidator
function disable_starship {
sed -i '' '/eval "$(starship init bash)"/s/^/#/' ~/.bashrc
}
function enable_starship {
sed -i '' 's/^#[[:space:]]*eval "$(starship init bash)"/eval "$(starship init bash)"/' ~/.bashrc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment