From 1d8cd1e56b70bd462956bec331ca3410986a8856 Mon Sep 17 00:00:00 2001 From: Tony Grosinger Date: Wed, 24 Jan 2018 08:09:21 -0800 Subject: [PATCH] Add kubectl info to ps1 --- .bashrc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.bashrc b/.bashrc index ab1e63b..2dff2b9 100644 --- a/.bashrc +++ b/.bashrc @@ -162,6 +162,20 @@ git_prompt () { echo " -- $git_color$git_branch${c_reset}" } -# Prompt -PS1="\n╔ \w -- \$(ls -1 | wc -l | sed 's: ::g') files\$(git_prompt)\n╚ \h\$ " +kubectl_context() { + context=$(kubectl config current-context 2>/dev/null) + namespace=$(kubectl config view -o "jsonpath={.contexts[?(@.name==\"$context\")].context.namespace}") + + prod_color=`tput setaf 1; tput bold` + dev_color=`tput setaf 4; tput bold` + + if [[ "$context" = *"hopcloud.extrahop.com"* ]]; then + echo "${prod_color}${context}:${namespace}${c_reset}" + else + echo "${dev_color}${context}:${namespace}${c_reset}" + fi +} + +# Prompt +PS1="\n╔ \w -- \$(ls -1 | wc -l | sed 's: ::g') files\$(git_prompt) -- \$(kubectl_context)\n╚ \h\$ "