1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-23 14:20:08 +00: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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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