Created
August 2, 2019 10:26
-
-
Save GeorgeMac/a069abc47cf727ef330d102cc0aa680b to your computer and use it in GitHub Desktop.
Right prompt for kubernetes context in zsh (requires oh-my-zsh)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local kube_cluster_color="yellow" | |
local kube_namespace_color="blue" | |
kube_ctx(){ | |
kubectl config get-contexts --no-headers $(kubectl config current-context) | |
} | |
kube_cluster() { | |
kube_ctx | awk '{ print $3 }' | |
} | |
kube_namespace() { | |
ns=$(kube_ctx | awk '{ print $5 }') | |
if [[ $ns != '' ]]; then | |
echo ":(%{$fg[$kube_namespace_color]%}$ns%{$fg[$kube_cluster_color]%})" | |
fi | |
} | |
RPROMPT='%{$fg[$kube_cluster_color]%}$(kube_cluster)$(kube_namespace)%{$reset_color%}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment