summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <erich.eckner.ext@bestsecret.com>2024-05-17 13:40:58 +0200
committerErich Eckner <erich.eckner.ext@bestsecret.com>2024-05-17 13:40:58 +0200
commita2dab1fce231c5c0cfe1aa809ea0e567be79160a (patch)
tree1bbaa02bece14b3356d6e0b1e95eaf8681bf0a61
parentfa8f6db09f0496adf419f7aa3391a5788d63514d (diff)
downloadbash-git-prompt-a2dab1fce231c5c0cfe1aa809ea0e567be79160a.tar.xz
track kubernetes context, too
-rw-r--r--bash-git-prompt.conf.in3
-rwxr-xr-xbash-git-prompt.in17
2 files changed, 20 insertions, 0 deletions
diff --git a/bash-git-prompt.conf.in b/bash-git-prompt.conf.in
index ebe1ab9..c0baf6b 100644
--- a/bash-git-prompt.conf.in
+++ b/bash-git-prompt.conf.in
@@ -1,3 +1,6 @@
#/bin/bash
skipDirRegEx='^$'
+
+kubectxRegExDev='-d-'
+kubectxRegExProd='-p-'
diff --git a/bash-git-prompt.in b/bash-git-prompt.in
index acc1a59..14640b9 100755
--- a/bash-git-prompt.in
+++ b/bash-git-prompt.in
@@ -14,6 +14,23 @@ PS1="$PS1Start"
. #ETCDIR#/bash-git-prompt.conf
+if currentContext=$(kubectl config current-context 2>/dev/null) \
+&& [ -n "${currentContext}" ]; then
+ if $mitFarbe; then
+ if toPrint=$(echo "${currentContext}" | grep -o -- "${kubectxRegExProd}"); then
+ PS1="$PS1\[\033[01;31m\]"
+ elif toPrint=$(echo "${currentContext}" | grep -o -- "${kubectxRegExDev}"); then
+ PS1="$PS1\[\033[01;34m\]"
+ else
+ toPrint="${currentContext}"
+ fi
+ fi
+ PS1="$PS1 ${toPrint}"
+ if $mitFarbe; then
+ PS1="$PS1\[\033[00m\]"
+ fi
+fi
+
skip=false
if [ -n "${skipDirRegEx}" ] && pwd | grep -q "${skipDirRegEx}" &> /dev/null
then