From 1fd41a3f8c33da32ca46be85303b275c8579d228 Mon Sep 17 00:00:00 2001
From: alchazov <chazov.alexey@gmail.com>
Date: Wed, 4 Aug 2021 16:34:19 +0500
Subject: [PATCH 1/2] Add KUBERNETES to prompt

---
 themes/agnoster.zsh-theme | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme
index fe7ddbac6..f99eecdfe 100644
--- a/themes/agnoster.zsh-theme
+++ b/themes/agnoster.zsh-theme
@@ -242,10 +242,45 @@ prompt_aws() {
   esac
 }
 
+#KUBERNETES icon:
+# - display KUBERNETES icon if context set
+# - displays red icon on black if context name contains 'prod'
+# - displays green icon on black if context name contains 'dev' or 'stage'
+# - displays yellow icon on black otherwise
+prompt_kubernetes_icon() {
+  KUBERNETES_SYMBOL=$'\xE2\x8E\x88'
+  KUBERNETES_CONTEXT=$1
+
+  case "$KUBERNETES_CONTEXT" in
+    *prod*) prompt_segment black red "$KUBERNETES_SYMBOL";;
+    *dev*|*stage*) prompt_segment black green "$KUBERNETES_SYMBOL";;
+    *) prompt_segment black yellow "$KUBERNETES_SYMBOL";;
+  esac
+
+}
+#KUBERNETES context:
+# - display current KUBERNETES context for connection
+# - from file .kube/config or env $KUBECONFIG
+# - displays context name
+# - displays namespace if set
+prompt_kubernetes() {
+  KUBERNETES_BINARY="${KUBERNETES_BINARY:-kubectl}"
+  [[ -z "$KUBECONFIG" && -z "$(${KUBERNETES_BINARY} config current-context 2>/dev/null)" ]] && return
+
+  KUBERNETES_CONTEXT="$(${KUBERNETES_BINARY} config current-context 2>/dev/null)"
+  KUBERNETES_CONTEXT="${KUBERNETES_CONTEXT:-N/A}"
+  KUBERNETES_NAMESPACE="$(${KUBERNETES_BINARY} config view --minify -o jsonpath={..namespace} 2>/dev/null)"
+  KUBERNETES_NAMESPACE="${KUBERNETES_NAMESPACE:+ ns:$KUBERNETES_NAMESPACE}"
+
+  prompt_kubernetes_icon "$KUBERNETES_CONTEXT"
+  prompt_segment $CURRENT_BG default "$KUBERNETES_CONTEXT$KUBERNETES_NAMESPACE"
+}
+
 ## Main prompt
 build_prompt() {
   RETVAL=$?
   prompt_status
+  prompt_kubernetes
   prompt_virtualenv
   prompt_aws
   prompt_context

From 9346c2418cdec900957ca1c6199506b2a78462da Mon Sep 17 00:00:00 2001
From: sybernatus <35989114+sybernatus@users.noreply.github.com>
Date: Tue, 21 Feb 2023 17:51:08 +0100
Subject: [PATCH 2/2] feat: add conditional formatting to agnoster

add conditional formatting for kubernetes to agnoster theme
---
 themes/agnoster.zsh-theme | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme
index f99eecdfe..81907cc24 100644
--- a/themes/agnoster.zsh-theme
+++ b/themes/agnoster.zsh-theme
@@ -261,30 +261,44 @@ prompt_kubernetes_icon() {
 #KUBERNETES context:
 # - display current KUBERNETES context for connection
 # - from file .kube/config or env $KUBECONFIG
-# - displays context name
-# - displays namespace if set
+# - displays kubernetes icon if $OMZ_THEME_AGNOSTER_KUBERNETES_ICON is not set to hidden
+# - displays context name if $OMZ_THEME_AGNOSTER_KUBERNETES_CONTEXT is not set to hidden
+# - displays namespace if $OMZ_THEME_AGNOSTER_KUBERNETES_NAMESPACE is not set to hidden
 prompt_kubernetes() {
   KUBERNETES_BINARY="${KUBERNETES_BINARY:-kubectl}"
   [[ -z "$KUBECONFIG" && -z "$(${KUBERNETES_BINARY} config current-context 2>/dev/null)" ]] && return
 
-  KUBERNETES_CONTEXT="$(${KUBERNETES_BINARY} config current-context 2>/dev/null)"
-  KUBERNETES_CONTEXT="${KUBERNETES_CONTEXT:-N/A}"
-  KUBERNETES_NAMESPACE="$(${KUBERNETES_BINARY} config view --minify -o jsonpath={..namespace} 2>/dev/null)"
-  KUBERNETES_NAMESPACE="${KUBERNETES_NAMESPACE:+ ns:$KUBERNETES_NAMESPACE}"
+  KUBERNETES_PROMPT=""
 
-  prompt_kubernetes_icon "$KUBERNETES_CONTEXT"
-  prompt_segment $CURRENT_BG default "$KUBERNETES_CONTEXT$KUBERNETES_NAMESPACE"
+  if [[ "$OMZ_THEME_AGNOSTER_KUBERNETES_CONTEXT" != "hidden" ]]; then
+    KUBERNETES_CONTEXT="$(${KUBERNETES_BINARY} config current-context 2>/dev/null)"
+    KUBERNETES_CONTEXT="${KUBERNETES_CONTEXT:-N/A}"
+    KUBERNETES_PROMPT="$KUBERNETES_PROMPT$KUBERNETES_CONTEXT"
+  fi
+
+  if [[ "$OMZ_THEME_AGNOSTER_KUBERNETES_NAMESPACE" != "hidden" ]]; then
+    KUBERNETES_NAMESPACE="$(${KUBERNETES_BINARY} config view --minify -o jsonpath={..namespace} 2>/dev/null)"
+    KUBERNETES_NAMESPACE="${KUBERNETES_NAMESPACE:+ ns:$KUBERNETES_NAMESPACE}"
+    KUBERNETES_PROMPT="$KUBERNETES_PROMPT -$KUBERNETES_NAMESPACE"
+  fi
+
+  if [[ "$KUBERNETES_PROMPT" != "" ]]; then
+    if [[ "$OMZ_THEME_AGNOSTER_KUBERNETES_ICON" != "hidden" ]]; then
+      prompt_kubernetes_icon "$KUBERNETES_CONTEXT"
+    fi
+    prompt_segment $CURRENT_BG default "$KUBERNETES_PROMPT"
+  fi
 }
 
 ## Main prompt
 build_prompt() {
   RETVAL=$?
   prompt_status
-  prompt_kubernetes
   prompt_virtualenv
   prompt_aws
   prompt_context
   prompt_dir
+  prompt_kubernetes
   prompt_git
   prompt_bzr
   prompt_hg