Skip to content

Instantly share code, notes, and snippets.

@mjpitz
Created March 9, 2021 04:14
Show Gist options
  • Save mjpitz/f53dfef034d12c2f101dfae03661851c to your computer and use it in GitHub Desktop.
Save mjpitz/f53dfef034d12c2f101dfae03661851c to your computer and use it in GitHub Desktop.
embed some kube context in your zsh shell
kubeconfig="${KUBECONFIG}"
if [[ -z "${kubeconfig}" ]]; then
kubeconfig="$(mktemp):$(ls -1 ${HOME}/.kube/*.yaml | tr $'\n' ':')${HOME}/.kube/config"
fi
export KUBECONFIG="${kubeconfig}"
function zsh_kube_prompt() {
zsh_kube_context=$(kubectl config current-context)
zsh_kube_authinfo=$(kubectl config get-contexts "${zsh_kube_context}" --no-headers | awk '{print $4}')
zsh_kube_ns=$(kubectl config get-contexts "${zsh_kube_context}" --no-headers | awk '{print $5}')
if [[ -z "${zsh_kube_ns}" ]]; then
zsh_kube_ns="default"
fi
echo "(${zsh_kube_authinfo}@${zsh_kube_context}/${zsh_kube_ns})"
}
RPROMPT='$(zsh_kube_prompt)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment