Created
March 9, 2021 04:14
-
-
Save mjpitz/f53dfef034d12c2f101dfae03661851c to your computer and use it in GitHub Desktop.
embed some kube context in your zsh shell
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
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