Hide kubecontext if there is no current context

This prevents a namespace from being shown on its own, when there's no context set to use it with anyway.
This commit is contained in:
Tim Malone 2019-03-20 01:31:10 +11:00 committed by GitHub
parent c4a8118b45
commit 4c081eba21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1696,6 +1696,10 @@ prompt_kubecontext() {
if [[ -n "$kubectl_version" ]]; then
# Get the current Kuberenetes context
local cur_ctx=$(kubectl config view -o=jsonpath='{.current-context}')
if [[ -z "${cur_ctx}" ]]; then
return
fi
cur_namespace="$(kubectl config view -o=jsonpath="{.contexts[?(@.name==\"${cur_ctx}\")].context.namespace}")"
# If the namespace comes back empty set it default.
if [[ -z "${cur_namespace}" ]]; then