aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2019-05-22 22:53:09 +0300
committerromkatv <roman.perepelitsa@gmail.com>2019-05-22 22:53:09 +0300
commitbc58a2c0ba6e825a01d51c2f047af15605882ca4 (patch)
tree572a2404e7f5d5725752cdd41badec3c827cf18c /powerlevel9k.zsh-theme
parenta49dc626f324e849757b730334939dc5a5b55cdf (diff)
speed up kubecontext prompt
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme28
1 files changed, 6 insertions, 22 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index cf6b9d95..9ff19bfc 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -2047,28 +2047,12 @@ prompt_dir_writable() {
################################################################
# Kubernetes Current Context/Namespace
prompt_kubecontext() {
- local kubectl_version="$(kubectl version --client 2>/dev/null)"
-
- if [[ -n "$kubectl_version" ]]; then
- # Get the current Kuberenetes context
- local cur_ctx=$(kubectl config view -o=jsonpath='{.current-context}')
- 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
- cur_namespace="default"
- fi
-
- local k8s_final_text=""
-
- if [[ "$cur_ctx" == "$cur_namespace" ]]; then
- # No reason to print out the same identificator twice
- k8s_final_text="$cur_ctx"
- else
- k8s_final_text="$cur_ctx/$cur_namespace"
- fi
-
- "$1_prompt_segment" "$0" "$2" "magenta" "white" "KUBERNETES_ICON" 0 '' "${k8s_final_text//\%/%%}"
- fi
+ (( $+commands[kubectl] )) || return
+ local ctx=$(command kubectl config view -o=jsonpath='{.current-context}')
+ [[ -n $ctx ]] || return
+ local ns="${$(command kubectl config view -o=jsonpath="{.contexts[?(@.name==\"$ctx\")].context.namespace}"):-default}"
+ [[ $ctx == $ns ]] || ctx+="/$ns"
+ "$1_prompt_segment" "$0" "$2" "magenta" "white" "KUBERNETES_ICON" 0 '' "${ctx//\%/%%}"
}
################################################################