Skip to content

Instantly share code, notes, and snippets.

@76creates
Last active January 11, 2022 11:48
Show Gist options
  • Save 76creates/432cc029fb17e41c618e3b9d52bc0253 to your computer and use it in GitHub Desktop.
Save 76creates/432cc029fb17e41c618e3b9d52bc0253 to your computer and use it in GitHub Desktop.
cycle up/down kubectl context
kd () {
kubectl config use-context $(
kubectl config get-contexts | awk 'NR == 2 { first=$1 } { if ($1 == "*") { if(getline == 1) { print $2 } else { print first }}}'
)
}
ku () {
kubectl config use-context $(
kubectl config get-contexts | awk 'BEGIN {previous=0} NR>1 { { if ($1 == "*") { if (previous!=0) {print previous} else { while (getline == 1){} print $2 } } } { previous=$2 } }'
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment