1
0
mirror of https://github.com/robbyrussell/oh-my-zsh.git synced 2026-02-13 12:50:58 +01:00

Add Kube Context to the default prompt

This commit is contained in:
Austin
2020-05-25 16:50:24 -06:00
committed by GitHub
parent 604f1ef9cd
commit 8c426ec0a7

View File

@@ -242,11 +242,27 @@ prompt_aws() {
esac
}
prompt_kubecontext() {
[[ -z "$(which kubectl)" ]] && return
local kube_prompt="k8s: "
local current_context="$(kubectl config current-context)"
local current_namespace="$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}')"
[[ -z "${current_context}" ]] && return
kube_prompt+="${current_context}"
[[ "${current_namespace}" ]] && [[ "${current_namespace}" != "default" ]]&& kube_prompt+="/${current_namespace}"
case "$kube_prompt" in
*prod*|*production*) prompt_segment red black "${kube_prompt}" ;;
*) prompt_segment cyan $CURRENT_FG "${kube_prompt}" ;;
esac
}
## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_virtualenv
prompt_kubecontext
prompt_aws
prompt_context
prompt_dir