Skip to content

Instantly share code, notes, and snippets.

@tmacam
Created September 29, 2023 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmacam/b53728096272aa4435fe413dce2a2a5c to your computer and use it in GitHub Desktop.
Save tmacam/b53728096272aa4435fe413dce2a2a5c to your computer and use it in GitHub Desktop.
dialog to change current kubectl context
#!/bin/bash
set -e
selected=$(
dialog --radiolist "Choose cluster" 0 0 0 $(
kubectl config get-contexts | sed -e 's/^ /off/' -e 's/^\*/on/' -e 1d | awk '{print $2,$3,$1 }'
) 2>&1 > /dev/tty
)
if [ "x${selected}" != "x" ]; then
echo Changing to context ${selected}
kubectl config use-context ${selected}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment