diff --git a/kubectx b/kubectx index c3271ea..f181552 100755 --- a/kubectx +++ b/kubectx @@ -26,14 +26,14 @@ KUBECTX="${HOME}/.kube/kubectx" usage() { cat <<"EOF" USAGE: - kubectx : list the contexts - kubectx : switch to context - kubectx - : switch to the previous context - kubectx = : rename context to - kubectx =. : rename current-context to - kubectx -d : delete context ('.' for current-context) - (this command won't delete the user/cluster entry - that is used by the context) + kubectx : list the contexts + kubectx : switch to context + kubectx - : switch to the previous context + kubectx = : rename context to + kubectx =. : rename current-context to + kubectx -d [] : delete context ('.' for current-context) + (this command won't delete the user/cluster entry + that is used by the context) kubectx -h,--help : show this message EOF @@ -148,6 +148,13 @@ rename_context() { kubectl config rename-context "${old_name}" "${new_name}" } +delete_contexts() { + IFS=' ' read -ra CTXS <<< "${1}" + for i in "${CTXS[@]}"; do + delete_context "${i}" + done +} + delete_context() { local ctx ctx="${1}" @@ -165,11 +172,8 @@ main() { if [[ "$#" -lt 2 ]]; then echo "error: missing context NAME" >&2 usage - elif [[ "$#" -gt 2 ]]; then - echo "error: too many arguments" >&2 - usage fi - delete_context "${2}" + delete_contexts "${@:2}" elif [[ "$#" -gt 1 ]]; then echo "error: too many arguments" >&2 usage