Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yuya-takeyama
Last active June 9, 2018 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuya-takeyama/d46639aee5043b4d748b9d3a422f8e3e to your computer and use it in GitHub Desktop.
Save yuya-takeyama/d46639aee5043b4d748b9d3a422f8e3e to your computer and use it in GitHub Desktop.
oh-my-zsh theme with kubernets current context and namespace
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