# ============================================================================ # ZSH CONFIGURATION FOR PLATFORM ENGINEER # Stack: Kubernetes, GCP, AWS, Azure, Terraform, Go, CI/CD # Author: Emre Cavunt # Web: emrecavunt.com # GitHub: github.com/emrecavunt # Gist: gist.github.com/emrecavunt # ============================================================================ # Self-documenting: Use #@ category: description before aliases/functions # Run `cheat` or `cheat ` to view available commands # Enable Powerlevel10k instant prompt (MUST stay at top) if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" fi # ============================================================================ # PATH CONFIGURATION (consolidated, no duplicates) # ============================================================================ export PATH="$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH" export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" export PATH="$HOME/google-cloud-sdk/bin:$PATH" # Required for gke-gcloud-auth-plugin export PATH="$HOME/.antigravity/antigravity/bin:$PATH" # ============================================================================ # OH MY ZSH CONFIGURATION # ============================================================================ export ZSH="$HOME/.oh-my-zsh" ZSH_THEME="powerlevel10k/powerlevel10k" # Performance optimizations zstyle ':omz:update' mode reminder # Don't block on updates DISABLE_UNTRACKED_FILES_DIRTY="true" # Faster git status in large repos # Plugins (kept minimal for speed) plugins=(git kubectl zsh-autosuggestions) # NOTE: Removed kube-ps1 - using P10k's native kubecontext instead (faster) source $ZSH/oh-my-zsh.sh # ============================================================================ # P10K CONFIGURATION # ============================================================================ [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh # ============================================================================ # LAZY LOADING (major startup time savings) # ============================================================================ # NVM Configuration export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && [ ! "$(command -v nvm)" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm only if not loaded nvm use default >/dev/null 2>&1 # Always ensure default version is used [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion # Lazy-load GVM (~100ms savings) if [[ -s "$HOME/.gvm/scripts/gvm" ]]; then gvm() { unset -f gvm go 2>/dev/null source "$HOME/.gvm/scripts/gvm" gvm "$@" } go() { unset -f go 2>/dev/null; gvm; go "$@"; } fi # Lazy-load gcloud completions (PATH is now set globally to fix kubectl auth) if [[ -f "$HOME/google-cloud-sdk/completion.zsh.inc" ]]; then gcloud() { unset -f gcloud gsutil bq . "$HOME/google-cloud-sdk/completion.zsh.inc" gcloud "$@" } gsutil() { unset -f gsutil; . "$HOME/google-cloud-sdk/completion.zsh.inc"; gsutil "$@"; } bq() { unset -f bq; . "$HOME/google-cloud-sdk/completion.zsh.inc"; bq "$@"; } fi # ============================================================================ # SELF-DOCUMENTING HELP SYSTEM # ============================================================================ # Usage: Add #@ category: description before any alias or function # Then run `cheat` to see all, or `cheat k8s` to filter by category cheat() { local filter="${1:-}" local zshrc="${ZDOTDIR:-$HOME}/.zshrc" echo "" echo "πŸš€ PLATFORM ENGINEER CHEAT SHEET" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" if [[ -n "$filter" ]]; then echo " Filtering by: $filter" fi # BSD awk compatible version - grouped by category awk -v filter="$filter" ' /^#@ / { line = $0 sub(/^#@ /, "", line) idx = index(line, ": ") if (idx > 0) { category = substr(line, 1, idx - 1) desc = substr(line, idx + 2) } else { category = line desc = "" } next_is_cmd = 1 next } next_is_cmd && /^alias [a-zA-Z0-9_-]+="/ { if (filter == "" || tolower(category) ~ tolower(filter)) { line = $0 sub(/^alias /, "", line) idx = index(line, "=") if (idx > 0) { cmd = substr(line, 1, idx - 1) # Store in array keyed by category if (!(category in cats)) { cats[category] = "" cat_order[++cat_count] = category } cats[category] = cats[category] sprintf(" %-14s %s\n", cmd, desc) } } next_is_cmd = 0 } next_is_cmd && /^[a-zA-Z0-9_-]+\(\)/ { if (filter == "" || tolower(category) ~ tolower(filter)) { cmd = $0 sub(/\(\).*/, "", cmd) if (!(category in cats)) { cats[category] = "" cat_order[++cat_count] = category } cats[category] = cats[category] sprintf(" %-14s %s\n", cmd, desc) } next_is_cmd = 0 } !/^#@ / && !/^alias / && !/^[a-zA-Z0-9_-]+\(\)/ { next_is_cmd = 0 } END { # Category display order and icons split("k8s k8s-debug tf tg gcp aws az docker git net util nav history fzf", order_arr) split("☸️ :πŸ”§:πŸ—οΈ :🌍:☁️ :πŸ”Ά:πŸ”·:🐳:πŸ“:🌐:βš™οΈ :πŸ“:πŸ“œ:πŸ”", icon_arr, ":") # Print in preferred order first for (i = 1; i <= 14; i++) { cat = order_arr[i] if (cat in cats) { printf "\n %s %s\n", icon_arr[i], toupper(cat) printf " ────────────────────────────────────────\n" printf "%s", cats[cat] delete cats[cat] } } # Print any remaining categories for (cat in cats) { printf "\n πŸ“Œ %s\n", toupper(cat) printf " ────────────────────────────────────────\n" printf "%s", cats[cat] } } ' "$zshrc" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " πŸ’‘ Usage: cheat [filter] Examples: cheat k8s, cheat aws, cheat git" echo "" } # ============================================================================ # KUBERNETES ALIASES # ============================================================================ #@ k8s: kubectl shortcut alias k="kubectl" #@ k8s: switch context (kubectx) alias kc="kubectx" #@ k8s: switch namespace (kubens) alias kn="kubens" #@ k8s: get resources alias kg="kubectl get" #@ k8s: get pods alias kgp="kubectl get pods" #@ k8s: get pods wide output alias kgpw="kubectl get pods -o wide" #@ k8s: get pods all namespaces alias kgpa="kubectl get pods --all-namespaces" #@ k8s: get services alias kgs="kubectl get svc" #@ k8s: get services all ns alias kgsa="kubectl get svc --all-namespaces" #@ k8s: get deployments alias kgd="kubectl get deploy" #@ k8s: get nodes alias kgn="kubectl get nodes" #@ k8s: get nodes wide alias kgno="kubectl get nodes -o wide" #@ k8s: get namespaces alias kgns="kubectl get namespaces" #@ k8s: get ingress alias kgi="kubectl get ingress" #@ k8s: get configmaps alias kgcm="kubectl get configmap" #@ k8s: get secrets alias kgsec="kubectl get secrets" #@ k8s: get persistent volumes alias kgpv="kubectl get pv" #@ k8s: get PVCs alias kgpvc="kubectl get pvc" #@ k8s: get storage classes alias kgsc="kubectl get storageclass" #@ k8s: get events sorted alias kgev="kubectl get events --sort-by='.lastTimestamp'" #@ k8s: describe resource alias kd="kubectl describe" #@ k8s: describe pod alias kdp="kubectl describe pod" #@ k8s: describe service alias kds="kubectl describe svc" #@ k8s: describe deployment alias kdd="kubectl describe deploy" #@ k8s: describe node alias kdn="kubectl describe node" #@ k8s: follow logs alias kl="kubectl logs -f" #@ k8s: logs previous container alias klp="kubectl logs -f --previous" #@ k8s: logs tail 100 alias klt="kubectl logs -f --tail=100" #@ k8s: exec into pod alias ke="kubectl exec -it" #@ k8s: exec sh into pod alias kesh="kubectl exec -it -- /bin/sh" #@ k8s: exec bash into pod alias kebash="kubectl exec -it -- /bin/bash" #@ k8s: apply manifest alias kaf="kubectl apply -f" #@ k8s: delete manifest alias kdf="kubectl delete -f" #@ k8s: replace manifest alias krf="kubectl replace -f" #@ k8s: delete resource alias kdel="kubectl delete" #@ k8s: edit resource alias ked="kubectl edit" #@ k8s: get as YAML alias kgy="kubectl get -o yaml" #@ k8s: get as JSON alias kgj="kubectl get -o json" #@ k8s: get wide output alias kgw="kubectl get -o wide" #@ k8s: rollout commands alias kro="kubectl rollout" #@ k8s: rollout status alias kros="kubectl rollout status" #@ k8s: rollout history alias kroh="kubectl rollout history" #@ k8s: rollout restart alias kror="kubectl rollout restart" #@ k8s: rollout undo alias krou="kubectl rollout undo" #@ k8s: top resources alias ktop="kubectl top" #@ k8s: top nodes alias ktopn="kubectl top nodes" #@ k8s: top pods alias ktopp="kubectl top pods" #@ k8s: port forward alias kpf="kubectl port-forward" # ============================================================================ # TERRAFORM ALIASES # ============================================================================ #@ tf: terraform alias tf="terraform" #@ tf: init alias tfi="terraform init" #@ tf: plan alias tfp="terraform plan" #@ tf: apply alias tfa="terraform apply" #@ tf: apply auto-approve alias tfaa="terraform apply -auto-approve" #@ tf: destroy alias tfd="terraform destroy" #@ tf: validate alias tfv="terraform validate" #@ tf: format recursive alias tff="terraform fmt -recursive" #@ tf: output alias tfo="terraform output" #@ tf: state commands alias tfs="terraform state" #@ tf: state list alias tfsl="terraform state list" #@ tf: state show alias tfss="terraform state show" #@ tf: workspace alias tfw="terraform workspace" #@ tf: workspace list alias tfwl="terraform workspace list" #@ tf: workspace select alias tfws="terraform workspace select" #@ tf: workspace new alias tfwn="terraform workspace new" #@ tf: refresh alias tfr="terraform refresh" #@ tf: import alias tfim="terraform import" #@ tf: console alias tfc="terraform console" #@ tf: graph alias tfg="terraform graph" #@ tf: providers alias tfpr="terraform providers" # ============================================================================ # TERRAGRUNT ALIASES # ============================================================================ #@ tg: terragrunt alias tg="terragrunt" #@ tg: init alias tgi="terragrunt init" #@ tg: plan alias tgp="terragrunt plan" #@ tg: apply alias tga="terragrunt apply" #@ tg: apply auto-approve alias tgaa="terragrunt apply -auto-approve" #@ tg: destroy alias tgd="terragrunt destroy" #@ tg: output alias tgo="terragrunt output" #@ tg: run-all apply alias tgra="terragrunt run-all apply" #@ tg: run-all plan alias tgrp="terragrunt run-all plan" #@ tg: run-all destroy alias tgrd="terragrunt run-all destroy" #@ tg: run-all init alias tgri="terragrunt run-all init" #@ tg: validate alias tgv="terragrunt validate" #@ tg: hcl format alias tghclfmt="terragrunt hclfmt" # ============================================================================ # GCP ALIASES # ============================================================================ #@ gcp: gcloud CLI alias gcp="gcloud" #@ gcp: config list alias gcl="gcloud config list" #@ gcp: config list all alias gcla="gcloud config list --all" #@ gcp: set project alias gcs="gcloud config set project" #@ gcp: configurations alias gcfg="gcloud config configurations" #@ gcp: configurations list alias gcfgl="gcloud config configurations list" #@ gcp: configurations activate alias gcfga="gcloud config configurations activate" #@ gcp: compute instances alias gci="gcloud compute instances list" #@ gcp: GKE clusters list alias gcr="gcloud container clusters list" #@ gcp: get GKE credentials alias gcrc="gcloud container clusters get-credentials" #@ gcp: IAM service accounts alias giam="gcloud iam service-accounts list" #@ gcp: list projects alias gproj="gcloud projects list" #@ gcp: Cloud SQL instances alias gsql="gcloud sql instances list" #@ gcp: read logs alias glog="gcloud logging read" #@ gcp: Cloud Run services alias grun="gcloud run services list" #@ gcp: Cloud Functions alias gfunc="gcloud functions list" #@ gcp: Pub/Sub topics alias gpub="gcloud pubsub topics list" #@ gcp: Pub/Sub subscriptions alias gsub="gcloud pubsub subscriptions list" # ============================================================================ # AWS ALIASES # ============================================================================ #@ aws: AWS CLI alias aws="aws" #@ aws: who am I (STS) alias awsw="aws sts get-caller-identity" #@ aws: current config alias awsr="aws configure list" #@ aws: list EC2 instances alias ec2l="aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PrivateIpAddress,Tags[?Key==\`Name\`].Value|[0]]' --output table" #@ aws: running EC2 instances alias ec2r="aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' --output table" #@ aws: list EKS clusters alias eksl="aws eks list-clusters" #@ aws: describe EKS cluster alias eksd="aws eks describe-cluster --name" #@ aws: update kubeconfig for EKS alias eksu="aws eks update-kubeconfig --name" #@ aws: list S3 buckets alias s3l="aws s3 ls" #@ aws: S3 copy alias s3cp="aws s3 cp" #@ aws: S3 sync alias s3sync="aws s3 sync" #@ aws: S3 remove alias s3rm="aws s3 rm" #@ aws: list IAM users alias iaml="aws iam list-users" #@ aws: list IAM roles alias iamr="aws iam list-roles" #@ aws: list IAM policies alias iamp="aws iam list-policies --scope Local" #@ aws: list ECR repos alias ecrl="aws ecr describe-repositories" #@ aws: login to ECR alias ecrlogin="aws ecr get-login-password --region \$(aws configure get region) | docker login --username AWS --password-stdin \$(aws sts get-caller-identity --query Account --output text).dkr.ecr.\$(aws configure get region).amazonaws.com" #@ aws: list Lambda functions alias laml="aws lambda list-functions" #@ aws: invoke Lambda alias lami="aws lambda invoke" #@ aws: list CloudWatch log groups alias cwl="aws logs describe-log-groups" #@ aws: tail CloudWatch logs alias cwtail="aws logs tail" #@ aws: list SSM instances alias ssml="aws ssm describe-instance-information" #@ aws: SSM session alias ssmsh="aws ssm start-session --target" # ============================================================================ # AZURE ALIASES # ============================================================================ #@ az: Azure CLI alias az="az" #@ az: login alias azl="az login" #@ az: current account alias azacc="az account show" #@ az: list accounts alias azaccl="az account list --output table" #@ az: set subscription alias azaccs="az account set --subscription" #@ az: list AKS clusters alias aksl="az aks list --output table" #@ az: get AKS credentials alias aksc="az aks get-credentials --resource-group" #@ az: show AKS cluster alias akss="az aks show --resource-group" #@ az: list VMs alias azvm="az vm list --output table" #@ az: show VM alias azvms="az vm show --resource-group" #@ az: list resource groups alias azrg="az group list --output table" #@ az: create resource group alias azrgc="az group create --name" #@ az: list storage accounts alias azsa="az storage account list --output table" #@ az: list ACR registries alias acrl="az acr list --output table" #@ az: login to ACR alias acrlogin="az acr login --name" #@ az: list VNets alias azvnet="az network vnet list --output table" #@ az: list NSGs alias aznsg="az network nsg list --output table" #@ az: list public IPs alias azpip="az network public-ip list --output table" # ============================================================================ # DOCKER ALIASES # ============================================================================ #@ docker: docker CLI alias d="docker" #@ docker: docker-compose alias dc="docker-compose" #@ docker: compose up detached alias dcu="docker-compose up -d" #@ docker: compose down alias dcd="docker-compose down" #@ docker: compose logs alias dcl="docker-compose logs -f" #@ docker: list containers alias dps="docker ps" #@ docker: list all containers alias dpsa="docker ps -a" #@ docker: list images alias di="docker images" #@ docker: exec into container alias dex="docker exec -it" #@ docker: follow logs alias dlogs="docker logs -f" #@ docker: remove container alias drm="docker rm" #@ docker: remove image alias drmi="docker rmi" #@ docker: system prune all alias dprune="docker system prune -af" #@ docker: list volumes alias dvol="docker volume ls" #@ docker: list networks alias dnet="docker network ls" #@ docker: stop all containers alias dstop="docker stop \$(docker ps -q)" #@ docker: kill all containers alias dkill="docker kill \$(docker ps -q)" #@ docker: build with tag alias dbuild="docker build -t" # ============================================================================ # GIT ALIASES (Extending Oh My Zsh git plugin) # ============================================================================ #@ git: git CLI alias g="git" #@ git: short status alias gs="git status -sb" #@ git: full status alias gss="git status" #@ git: add all alias gaa="git add --all" #@ git: interactive add alias gapa="git add --patch" #@ git: commit with message alias gcm="git commit -m" #@ git: add and commit alias gcam="git commit -am" #@ git: amend commit alias gca="git commit --amend" #@ git: amend no edit alias gcan="git commit --amend --no-edit" #@ git: amend with new date alias gcane="git commit --amend --no-edit --date=now" #@ git: force push safely alias gpf="git push --force-with-lease" #@ git: pull rebase alias gpl="git pull --rebase" #@ git: pull and push alias gplp="git pull --rebase && git push" #@ git: fetch all and pull alias gup="git fetch --all --prune && git pull --rebase" #@ git: log graph alias glog="git log --oneline --graph --decorate -20" #@ git: log all branches alias gloga="git log --oneline --graph --decorate --all -30" #@ git: log pretty format alias glogp="git log --pretty=format:'%C(yellow)%h%Creset %C(cyan)%ad%Creset %s %C(green)(%an)%Creset' --date=short" #@ git: diff color words alias gdiff="git diff --color-words" #@ git: diff staged alias gds="git diff --staged" #@ git: quick WIP commit alias gwip="git add -A && git commit -m 'WIP'" #@ git: undo WIP commit alias gunwip="git log -1 --format='%s' | grep -q 'WIP' && git reset HEAD~1" #@ git: delete merged branches alias gclean="git branch --merged | grep -v '\*\|main\|master\|develop' | xargs -n 1 git branch -d" #@ git: fetch and prune alias gfp="git fetch --prune" #@ git: rebase alias grb="git rebase" #@ git: interactive rebase alias grbi="git rebase -i" #@ git: rebase continue alias grbc="git rebase --continue" #@ git: rebase abort alias grba="git rebase --abort" #@ git: checkout previous branch alias gco-="git checkout -" #@ git: checkout new branch alias gcob="git checkout -b" #@ git: switch branch alias gsw="git switch" #@ git: switch create branch alias gswc="git switch -c" #@ git: restore file alias grs="git restore" #@ git: restore staged alias grss="git restore --staged" #@ git: stash changes alias gst="git stash" #@ git: stash pop alias gstp="git stash pop" #@ git: stash list alias gstl="git stash list" #@ git: stash apply alias gsta="git stash apply" #@ git: stash drop alias gstd="git stash drop" #@ git: stash show alias gsts="git stash show -p" #@ git: blame file alias gbl="git blame" #@ git: cherry-pick alias gcp="git cherry-pick" #@ git: cherry-pick continue alias gcpc="git cherry-pick --continue" #@ git: cherry-pick abort alias gcpa="git cherry-pick --abort" #@ git: list tags alias gtag="git tag" #@ git: list tags pattern alias gtagl="git tag -l" #@ git: show remotes alias grem="git remote -v" #@ git: worktree commands alias gwt="git worktree" #@ git: shallow clone gclone() { git clone --depth=1 "$@"; } #@ git: find file in history gfind() { git log --all --full-history -- "**/$1"; } # ============================================================================ # NETWORKING & DEBUGGING ALIASES # ============================================================================ #@ net: external IP alias myip="curl -s ifconfig.me" #@ net: local IP alias myiplocal="ifconfig | awk '/inet /&&!/127.0.0.1/{print \$2;exit}'" #@ net: listening ports alias ports="lsof -i -P -n | grep LISTEN" #@ net: all listening alias listening="netstat -an | grep LISTEN" #@ net: dig short alias diga="dig +short" #@ net: dig answer only alias digall="dig +noall +answer" #@ net: dig MX records alias digmx="dig MX" #@ net: dig NS records alias digns="dig NS" #@ net: dig trace alias digtrace="dig +trace" #@ net: nslookup alias nsl="nslookup" #@ net: flush DNS cache alias flush-dns="sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder" #@ net: curl headers only alias curlh="curl -I" #@ net: curl with JSON header alias curlj="curl -H 'Content-Type: application/json'" #@ net: curl with timing alias curlt="curl -o /dev/null -s -w 'DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n'" #@ net: curl SSL debug alias curlssl="curl -vI --ssl" #@ net: wget resume alias wget="wget -c" #@ net: check SSL cert alias sslcheck="openssl s_client -connect" #@ net: show SSL certs alias sslcert="openssl s_client -showcerts -connect" #@ net: SSL expiry dates unalias sslexpiry 2>/dev/null # Prevent alias conflict on reload sslexpiry() { local host=$1 if [[ -z "$host" ]]; then echo "Usage: sslexpiry " return 1 fi if [[ "$host" != *":"* ]]; then host="$host:443" fi # Use SNI (-servername) which is often required openssl s_client -servername "${host%%:*}" -connect "$host" 2>/dev/null | openssl x509 -noout -dates } #@ net: ping google alias pingg="ping -c 5 google.com" #@ net: ping 8.8.8.8 alias ping8="ping -c 5 8.8.8.8" #@ net: traceroute alias tracert="traceroute" #@ net: ARP table alias arp="arp -a" #@ net: routing table alias routes="netstat -rn" #@ net: all interfaces alias ifinfo="ifconfig -a" # ============================================================================ # KUBERNETES NETWORK DEBUGGING FUNCTIONS # ============================================================================ #@ k8s-debug: netshoot pod testbox() { kubectl run testbox-$(date +%s) --rm -i --tty \ --image=nicolaka/netshoot \ --restart=Never \ -- /bin/bash } #@ k8s-debug: netshoot with hostNetwork testbox-host() { kubectl run testbox-host-$(date +%s) --rm -i --tty \ --image=nicolaka/netshoot \ --restart=Never \ --overrides='{ "spec": { "hostNetwork": true, "containers": [{ "name": "testbox", "image": "nicolaka/netshoot", "stdin": true, "tty": true }] } }' \ -- /bin/bash } #@ k8s-debug: minimal busybox pod busybox() { kubectl run busybox-$(date +%s) --rm -i --tty \ --image=busybox \ --restart=Never \ -- /bin/sh } #@ k8s-debug: debug node with netshoot knode-debug() { local node=${1:-$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')} kubectl debug node/"$node" -it --image=nicolaka/netshoot } #@ k8s-debug: DNS debugging pod kdns-debug() { kubectl run dnsutils-$(date +%s) --rm -i --tty \ --image=gcr.io/kubernetes-e2e-test-images/dnsutils:1.3 \ --restart=Never \ -- /bin/sh } #@ k8s-debug: ping from pod kping() { local pod=$1 local target=$2 kubectl exec -it "$pod" -- ping -c 3 "$target" } #@ k8s-debug: nslookup from pod kpod-nslookup() { local pod=$1 local domain=$2 kubectl exec -it "$pod" -- nslookup "$domain" } #@ k8s-debug: curl from pod kcurl() { local pod=$1 shift kubectl exec -it "$pod" -- curl "$@" } #@ k8s-debug: port forward service kpfw() { local svc=$1 local local_port=${2:-8080} local remote_port=${3:-80} echo "Forwarding localhost:$local_port -> $svc:$remote_port (Ctrl+C to stop)" kubectl port-forward svc/"$svc" "$local_port":"$remote_port" } #@ k8s-debug: list pod IPs kpod-ips() { kubectl get pods -o custom-columns="NAME:.metadata.name,IP:.status.podIP,NODE:.spec.nodeName" } #@ k8s-debug: get endpoints kget-ep() { kubectl get endpoints "$@" } #@ k8s-debug: get network policies kget-np() { kubectl get networkpolicies "$@" } # ============================================================================ # PLATFORM ENGINEER UTILITY FUNCTIONS # ============================================================================ #@ util: show all platform contexts ctx() { echo "☸️ K8s Context: $(kubectl config current-context 2>/dev/null || echo 'none')" echo "☸️ K8s NS: $(kubectl config view --minify -o jsonpath='{..namespace}' 2>/dev/null || echo 'default')" echo "☁️ GCP Project: $(gcloud config get-value project 2>/dev/null || echo 'none')" echo "πŸ”Ά AWS Profile: ${AWS_PROFILE:-default}" echo "πŸ”· Azure Sub: $(az account show --query name -o tsv 2>/dev/null || echo 'none')" echo "πŸ“ TF Workspace: $(terraform workspace show 2>/dev/null || echo 'N/A')" } #@ util: decode k8s secret kdecode() { local secret=$1 local key=$2 if [[ -z "$key" ]]; then kubectl get secret "$secret" -o json | jq -r '.data | to_entries[] | "\(.key): \(.value | @base64d)"' else kubectl get secret "$secret" -o jsonpath="{.data.$key}" | base64 -d fi } #@ util: view resource as YAML kyaml() { kubectl get "$@" -o yaml | ${EDITOR:-vim} } #@ util: watch pods kwatch() { watch -n 1 "kubectl get pods $*" } #@ util: get all resources in namespace kall() { kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n "${1:-default}" } #@ util: pretty print JSON json() { cat "$@" | jq '.' } #@ util: YAML to JSON y2j() { cat "$@" | yq -o=json } #@ util: JSON to YAML j2y() { cat "$@" | yq -P } #@ util: base64 encode b64e() { echo -n "$1" | base64; } #@ util: base64 decode b64d() { echo -n "$1" | base64 -d; } #@ util: generate random password genpass() { openssl rand -base64 ${1:-32} | tr -d '/+=' | head -c ${1:-32} } #@ util: generate UUID uuid() { uuidgen | tr '[:upper:]' '[:lower:]' } #@ util: ISO timestamp ts() { date +%Y-%m-%dT%H:%M:%S%z } #@ util: Unix timestamp uts() { date +%s } #@ util: check tool versions versions() { echo "πŸ“Š TOOL VERSIONS" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" # Helper to print version check_ver() { local cmd=$1 local name=$2 local flag=${3:---version} if command -v "$cmd" &> /dev/null; then # Use ${=flag} for word splitting in zsh ver=$($cmd ${=flag} 2>&1) # Clean up output based on command if [[ "$cmd" == "az" ]]; then ver=$(echo "$ver" | grep "azure-cli" | head -n 1) else ver=$(echo "$ver" | head -n 1) fi printf " %-12s %s\n" "$name" "$ver" else printf " %-12s %s\n" "$name" "Not installed" fi } check_ver "go" "Go" "version" check_ver "node" "Node" "--version" check_ver "python3" "Python" "--version" check_ver "terraform" "Terraform" "--version" check_ver "terragrunt" "Terragrunt" "--version" check_ver "kubectl" "Kubectl" "version --client" check_ver "gcloud" "GCloud" "version" check_ver "aws" "AWS" "--version" check_ver "az" "Azure" "--version" check_ver "docker" "Docker" "--version" echo "" } # ============================================================================ # NAVIGATION & PRODUCTIVITY # ============================================================================ #@ nav: go up one directory alias ..="cd .." #@ nav: go up two directories alias ...="cd ../.." #@ nav: go up three directories alias ....="cd ../../.." #@ nav: list all with details alias ll="ls -lah" #@ nav: list hidden files alias la="ls -A" #@ nav: list compact alias l="ls -CF" #@ nav: clear screen alias cls="clear" #@ nav: show history alias h="history" #@ nav: search history alias hg="history | grep" #@ nav: mkdir with parents alias mkdir="mkdir -pv" #@ nav: safe copy alias cp="cp -iv" #@ nav: safe move alias mv="mv -iv" #@ nav: safe remove alias rm="rm -iv" #@ nav: disk usage human alias df="df -h" #@ nav: directory size human alias du="du -h" #@ nav: directory size depth 1 alias dud="du -d 1 -h" #@ nav: memory stats alias free="vm_stat" #@ nav: edit zshrc alias zshrc="$EDITOR ~/.zshrc" #@ nav: reload zshrc alias reload="source ~/.zshrc && echo 'zshrc reloaded!'" #@ nav: edit /etc/hosts alias hosts="sudo $EDITOR /etc/hosts" #@ nav: edit SSH config alias sshconfig="$EDITOR ~/.ssh/config" # ============================================================================ # FZF INTEGRATION (if installed) # ============================================================================ if command -v fzf &> /dev/null; then #@ fzf: fuzzy find files alias ff="fzf --preview 'cat {}'" #@ fzf: fuzzy k8s context switch kctx() { kubectl config use-context $(kubectl config get-contexts -o name | fzf) } #@ fzf: fuzzy namespace switch kns-fzf() { kubectl config set-context --current --namespace=$(kubectl get ns -o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | fzf) } #@ fzf: fuzzy git branch checkout gbf() { git checkout $(git branch -a | fzf | sed 's/remotes\/origin\///' | xargs) } #@ fzf: fuzzy git log glf() { git log --oneline | fzf --preview 'git show {1}' } fi # ============================================================================ # EDITOR PREFERENCE # ============================================================================ export EDITOR="${EDITOR:-vim}" export VISUAL="${VISUAL:-vim}" # ============================================================================ # HISTORY CONFIGURATION # ============================================================================ HISTSIZE=50000 SAVEHIST=50000 HISTFILE=~/.zsh_history setopt EXTENDED_HISTORY # Write timestamp to history setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicates first setopt HIST_IGNORE_DUPS # Don't record duplicates setopt HIST_IGNORE_SPACE # Don't record commands starting with space setopt HIST_VERIFY # Show command before executing from history setopt SHARE_HISTORY # Share history between sessions #@ history: full history with timestamps alias hist="fc -li 1" #@ history: last 50 with timestamps alias histn="fc -li -50" #@ history: with elapsed time alias histt="fc -liD 1" #@ history: show all history alias history="fc -l 1" # ============================================================================ # GITHUB COPILOT CLI FUNCTIONS # ============================================================================ ghcs() { FUNCNAME="$funcstack[1]" TARGET="shell" local GH_DEBUG="$GH_DEBUG" local GH_HOST="$GH_HOST" read -r -d '' __USAGE <<-EOF Wrapper around \`gh copilot suggest\` to suggest a command based on a natural language description. USAGE $FUNCNAME [flags] FLAGS -d, --debug Enable debugging -h, --help Display help usage --hostname The GitHub host to use for authentication -t, --target target Target for suggestion; must be shell, gh, git default: "$TARGET" EOF local OPT OPTARG OPTIND while getopts "dht:-:" OPT; do if [ "$OPT" = "-" ]; then OPT="${OPTARG%%=*}" OPTARG="${OPTARG#"$OPT"}" OPTARG="${OPTARG#=}" fi case "$OPT" in debug | d) GH_DEBUG=api ;; help | h) echo "$__USAGE"; return 0 ;; hostname) GH_HOST="$OPTARG" ;; target | t) TARGET="$OPTARG" ;; esac done shift "$((OPTIND-1))" TMPFILE="$(mktemp -t gh-copilotXXXXXX)" trap 'rm -f "$TMPFILE"' EXIT if GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot suggest -t "$TARGET" "$@" --shell-out "$TMPFILE"; then if [ -s "$TMPFILE" ]; then FIXED_CMD="$(cat $TMPFILE)" print -s -- "$FIXED_CMD" echo eval -- "$FIXED_CMD" fi else return 1 fi } ghce() { FUNCNAME="$funcstack[1]" local GH_DEBUG="$GH_DEBUG" local GH_HOST="$GH_HOST" read -r -d '' __USAGE <<-EOF Wrapper around \`gh copilot explain\` to explain a given input command in natural language. USAGE $FUNCNAME [flags] FLAGS -d, --debug Enable debugging -h, --help Display help usage --hostname The GitHub host to use for authentication EOF local OPT OPTARG OPTIND while getopts "dh-:" OPT; do if [ "$OPT" = "-" ]; then OPT="${OPTARG%%=*}" OPTARG="${OPTARG#"$OPT"}" OPTARG="${OPTARG#=}" fi case "$OPT" in debug | d) GH_DEBUG=api ;; help | h) echo "$__USAGE"; return 0 ;; hostname) GH_HOST="$OPTARG" ;; esac done shift "$((OPTIND-1))" GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot explain "$@" } # ============================================================================ # END OF ZSHRC # ============================================================================ # Self-documenting: Run `cheat` to see all commands, `cheat k8s` to filter # Benchmark: Run `for i in $(seq 1 5); do /usr/bin/time zsh -i -c exit; done`