Skip to content

Instantly share code, notes, and snippets.

@GeorgeMac
Created August 2, 2019 10:26
Show Gist options
  • Save GeorgeMac/a069abc47cf727ef330d102cc0aa680b to your computer and use it in GitHub Desktop.
Save GeorgeMac/a069abc47cf727ef330d102cc0aa680b to your computer and use it in GitHub Desktop.
Right prompt for kubernetes context in zsh (requires oh-my-zsh)
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