Skip to content

Instantly share code, notes, and snippets.

@quangnhut123
Created March 8, 2023 07:29
Show Gist options
  • Save quangnhut123/ce9a7eaea16644fd495fe9d2ec63489e to your computer and use it in GitHub Desktop.
Save quangnhut123/ce9a7eaea16644fd495fe9d2ec63489e to your computer and use it in GitHub Desktop.
kubecontext=$(kubectl config view -o jsonpath='{.contexts[*].name}')
oldIFS=$IFS
IFS=$' '
choices=( $kubecontext )
IFS=$oldIFS
PS3="Please select your kube context: "
select answer in "${choices[@]}"; do
for item in "${choices[@]}"; do
if [[ $item == $answer ]]; then
break 2
fi
done
done
kubectl config use-context $answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment