Skip to content

Commit

Permalink
Option to toggle Kubernetes namespace display(spaceship-prompt#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
nomaed authored and dedene committed Feb 23, 2019
1 parent 823992a commit ecc56d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ Shows the active kubectl context, which consists of a cluster name and, when wor
| `SPACESHIP_KUBECONTEXT_SUFFIX` | `$SPACESHIP_PROMPT_DEFAULT_SUFFIX` | Suffix after Kubectl context section |
| `SPACESHIP_KUBECONTEXT_SYMBOL` | `☸️·` | Character to be shown before Kubectl context |
| `SPACESHIP_KUBECONTEXT_COLOR` | `cyan` | Color of Kubectl context section |
| `SPACESHIP_KUBECONTEXT_NAMESPACE_SHOW` | `true` | Should namespace be also displayed |

### Terraform workspace (`terraform`)

Expand Down
7 changes: 5 additions & 2 deletions sections/kubecontext.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SPACESHIP_KUBECONTEXT_SUFFIX="${SPACESHIP_KUBECONTEXT_SUFFIX="$SPACESHIP_PROMPT_
# See: https://github.com/denysdovhan/spaceship-prompt/pull/432
SPACESHIP_KUBECONTEXT_SYMBOL="${SPACESHIP_KUBECONTEXT_SYMBOL="☸️ "}"
SPACESHIP_KUBECONTEXT_COLOR="${SPACESHIP_KUBECONTEXT_COLOR="cyan"}"
SPACESHIP_KUBECONTEXT_NAMESPACE_SHOW="${SPACESHIP_KUBECONTEXT_NAMESPACE_SHOW=true}"

# ------------------------------------------------------------------------------
# Section
Expand All @@ -30,8 +31,10 @@ spaceship_kubecontext() {
local kube_context=$(kubectl config current-context 2>/dev/null)
[[ -z $kube_context ]] && return

local kube_namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null)
[[ -n $kube_namespace && "$kube_namespace" != "default" ]] && kube_context="$kube_context ($kube_namespace)"
if [[ $SPACESHIP_KUBECONTEXT_NAMESPACE_SHOW == true ]]; then
local kube_namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null)
[[ -n $kube_namespace && "$kube_namespace" != "default" ]] && kube_context="$kube_context ($kube_namespace)"
fi

spaceship::section \
"$SPACESHIP_KUBECONTEXT_COLOR" \
Expand Down

0 comments on commit ecc56d1

Please sign in to comment.