Add kube context to prompt

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-09-16 14:16:38 +02:00
parent 6059afdaa9
commit ea39a9ea85
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -101,6 +101,21 @@ function prompt_gomod() {
[[ ${mod} == ${mod_default} ]] || echo "${bracket_open} %{$fg[yellow]%}${mod} ${bracket_close}" [[ ${mod} == ${mod_default} ]] || echo "${bracket_open} %{$fg[yellow]%}${mod} ${bracket_close}"
} }
function prompt_kubectx() {
command -v kubectl >/dev/null || return 0
local ctx="$(kubectl config current-context 2>/dev/null || echo "")"
local color="yellow"
[[ -n $ctx ]] || return 0
case "${ctx}" in
minikube) color="green" ;;
prod) color="red" ;;
esac
echo "${bracket_open} %{$fg[${color}]%}${ctx} ${bracket_close}"
}
local current_dir='$(short_path)' local current_dir='$(short_path)'
local git_info='$(build_git_prompt)' local git_info='$(build_git_prompt)'
@ -114,9 +129,10 @@ local prompt_part_exit="%(?..${bracket_open} %{$fg[red]%}%?%{${reset_color}%} ${
local prompt_part_char='$(prompt_char)' local prompt_part_char='$(prompt_char)'
local prompt_part_configgit='$(config-git_prompt)' local prompt_part_configgit='$(config-git_prompt)'
local prompt_part_gomod='$(prompt_gomod)' local prompt_part_gomod='$(prompt_gomod)'
local prompt_part_kubectx='$(prompt_kubectx)'
PROMPT=" PROMPT="
╭─ ${prompt_part_time}${prompt_part_user}${prompt_part_configgit}${prompt_part_gomod}${prompt_part_exit} ${prompt_part_path} ╭─ ${prompt_part_time}${prompt_part_user}${prompt_part_configgit}${prompt_part_gomod}${prompt_part_kubectx}${prompt_part_exit} ${prompt_part_path}
╰─ " ╰─ "
RPROMPT="${git_info}" RPROMPT="${git_info}"