Last active
June 9, 2018 19:31
-
-
Save yuya-takeyama/d46639aee5043b4d748b9d3a422f8e3e to your computer and use it in GitHub Desktop.
oh-my-zsh theme with kubernets current context and namespace
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
kube-prompt-info () { | |
local KUBECTL_CMD | |
local _kube_current_context | |
local _kube_current_namespace | |
KUBECTL_CMD="kubectl" | |
if ! hash "${KUBECTL_CMD}" 2> /dev/null; then | |
else | |
_current_kube_context=$(kubectl config current-context) | |
_current_kube_namespace=$(kubectl config view -o=jsonpath="{.contexts[?(@.name==\"${_current_kube_context}\")].context.namespace}") | |
echo "${ZSH_THEME_KUBE_PROMPT_PREFIX}${_current_kube_context}/${_current_kube_namespace}${ZSH_THEME_KUBE_PROMPT_SUFFIX}" | |
fi | |
} | |
PROMPT='%{$fg[red]%}%m%{$reset_color%}:%{$fg[green]%}%c%{$reset_color%}$(git_prompt_info)$(kube-prompt-info) %(!.#.$) ' | |
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[blue]%}(" | |
ZSH_THEME_GIT_PROMPT_SUFFIX=")%{$reset_color%}" | |
ZSH_THEME_KUBE_PROMPT_PREFIX=" %{$fg[yellow]%}(" | |
ZSH_THEME_KUBE_PROMPT_SUFFIX=")%{$reset_color%}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment