zsh: update kubectl prompt setup
Alan Pearce alan@alanpearce.eu
Fri, 08 Nov 2019 14:14:35 +0100
1 files changed, 8 insertions(+), 15 deletions(-)
jump to
M user/zsh/.config/zsh/.zshrc → user/zsh/.config/zsh/.zshrc
@@ -87,29 +87,22 @@ AGKOZAK_PROMPT_DIRTRIM=0 AGKOZAK_LEFT_PROMPT_ONLY=${+SSH_CLIENT} check_kubectl_context () { - if [[ "$PWD" =~ /kubernetes ]] + if [[ "$PWD" =~ /kubernetes || "$PWD" =~ /monorepo ]] then - git_branch=$(git rev-parse --abbrev-ref HEAD | tr '[:upper:]' '[:lower:]') kubectl_context=$(kubectl config current-context) kubectl_namespace=$(kubectl config view -o jsonpath="{.contexts[?(@.name==\"${kubectl_context}\")].context.namespace}") - case $git_branch in - staging) - kubectl_release=satoshipay-${kubectl_namespace}-staging - ;; - production) - kubectl_release=satoshipay-${kubectl_namespace} - ;; - master) - kubectl_release= - ;; - *) - kubectl_release=story-${git_branch}-${kubectl_namespace} - esac if [[ $kubectl_context =~ production ]] then kubectl_colour=red + kubectl_release=satoshipay-${kubectl_namespace} else kubectl_colour=yellow + if [[ -z $mr ]] + then + kubectl_release=satoshipay-${kubectl_namespace}-staging + else + kubectl_release=story-${mr}-${kubectl_namespace} + fi fi prompt_context="%F{$kubectl_colour}[${kubectl_context}:${kubectl_namespace}]%f" else