Last active
October 15, 2023 06:29
-
-
Save mikesparr/ce87bfb603bbbd2e9c55464e8a0361ac to your computer and use it in GitHub Desktop.
Example helpers in zshrc file for Mac computer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .zshrc | |
# other stuff already in file | |
# ------------------------------ my helpers ------------------------------------ | |
# DoiT Shortcuts Help | |
function shortcuts { | |
echo "ENV vars:" | |
echo " - ORGANIZATION ($ORGANIZATION)" | |
echo " - BILLING ($BILLING)" | |
echo " - FOLDER ($FOLDER)" | |
echo " - PROJECT_ID ($PROJECT_ID)" | |
echo | |
echo "Aliases:" | |
echo " - experiment (stub setup.sh and open browser)" | |
echo " - createproject {project-id}" | |
echo " - linkbilling {project-id}" | |
echo " - myprojects" | |
echo " - checkbilling" | |
echo " - newproject (requires PROJECT_ID env var)" | |
echo " - myip" | |
echo " - checkurl (requires URL env var)" | |
echo " - flushdns" | |
} | |
# Python 3 alias | |
alias python=/opt/homebrew/bin/python3 | |
alias pip=/opt/homebrew/bin/pip3 | |
# Get my IP address | |
alias myip="/usr/bin/curl ident.me; echo" | |
# Poll a URL for response code | |
export URL="https://example.com" | |
alias checkurl="while true; do curl -s -o /dev/null -w '%{http_code}\n' $URL; sleep 1; done" | |
# DoiT GCP Playground Shortcuts | |
export ORGANIZATION=#CHANGEME | |
export BILLING=#CHANGEME | |
export FOLDER=#CHANGEME | |
alias createproject="gcloud projects create --folder=$FOLDER --project" | |
alias myprojects="gcloud projects list --filter=parent.id=$FOLDER" | |
alias linkbilling="gcloud beta billing projects link --billing-account=$BILLING" | |
alias checkbilling="gcloud beta billing projects describe $(gcloud config get-value project) --format='value(billingEnabled)'" | |
#alias newproject="gcloud projects create $PROJECT_ID --folder $FOLDER && linkbilling $PROJECT_ID && gcloud config set project $PROJECT_ID" | |
alias context="shortcuts" | |
function newproject { | |
gcloud projects create $PROJECT_ID --folder $FOLDER && linkbilling $PROJECT_ID && gcloud config set project $PROJECT_ID | |
} | |
# Other helpers | |
alias flushdns="dscacheutil -flushcache;sudo killall -HUP mDNSResponder" | |
complete -o nospace -C /usr/local/bin/vault vault | |
# Service Account Helper | |
export IMPERSONATE='gcloud config set auth/impersonate_service_account' | |
impersonate() { | |
sa=$1 | |
echo "Impersonating $sa" | |
gcloud config set auth/impersonate_service_account $sa | |
} | |
sa() { | |
case $1 in | |
tf) | |
impersonate [email protected] | |
;; | |
clear) | |
gcloud config unset auth/impersonate_service_account | |
;; | |
*) | |
echo "Usage: Updates impersonated service account" | |
echo " gsa [gke|admin|clear]" | |
esac | |
} | |
# setup.sh experiment file header | |
function experiment { | |
cat > setup.sh << EOF | |
#!/usr/bin/env bash | |
##################################################################### | |
# REFERENCES | |
# - URL | |
##################################################################### | |
export PROJECT_ID=\$(gcloud config get-value project) | |
export PROJECT_USER=\$(gcloud config get-value core/account) # set current user | |
export PROJECT_NUMBER=\$(gcloud projects describe \$PROJECT_ID --format="value(projectNumber)") | |
export IDNS=\${PROJECT_ID}.svc.id.goog # workflow identity domain | |
export GCP_REGION="us-central1" # CHANGEME (OPT) | |
export GCP_ZONE="us-central1-a" # CHANGEME (OPT) | |
export NETWORK_NAME="default" | |
# enable apis | |
gcloud services enable compute.googleapis.com \\ | |
storage.googleapis.com | |
# configure gcloud sdk | |
gcloud config set compute/region \$GCP_REGION | |
gcloud config set compute/zone \$GCP_ZONE | |
EOF | |
# open new browser window to cloud console | |
open -na "Google Chrome" --args --new-window "https://console.cloud.google.com" | |
} | |
# helper function to share sensitive strings (echo test | o) | |
o () { cat "$@" | curl -sF 'msg=<-' https://onetime.doit-intl.com/secret | jq -r .token | awk {'print "https://onetime.doit-intl.com/getmsg?token="$1'}; } | |
# ---------------------------- /end my helpers -------------------------------- | |
# The next line updates PATH for the Google Cloud SDK. | |
if [ -f '/Users/mike/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/mike/google-cloud-sdk/path.zsh.inc'; fi | |
# The next line enables shell command completion for gcloud. | |
if [ -f '/Users/mike/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/mike/google-cloud-sdk/completion.zsh.inc'; fi | |
# kubectl helpers | |
source <(kubectl completion zsh) | |
alias k=kubectl | |
compdef __start_kubectl k | |
# after install krew, set path | |
# https://krew.sigs.k8s.io/docs/user-guide/setup/install/ | |
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" | |
# unalias gam from Oh My Zsh | |
unalias -m gam | |
function gam() { "/Users/mike/bin/gam/gam" "$@" ; } | |
# add gcpdiag tool to path | |
function gcpdiag() { "/Users/mike/google-cloud-diag/gcpdiag" "$@" ; } | |
# add android sdk command-line-tools to path | |
export PATH="/Users/mike/Library/Android/sdk/cmdline-tools/latest/bin:$PATH" | |
export PATH="/opt/homebrew/opt/openjdk/bin:$PATH" | |
export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include" | |
export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH" | |
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment