From 7ac1963235c0d776a66b6eb5f07f78fe6bce19cb Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Tue, 28 Mar 2017 17:36:51 -0700 Subject: [PATCH] Show current context with colors Signed-off-by: Ahmet Alp Balkan --- kubectx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kubectx b/kubectx index 8126bc1..06572b2 100755 --- a/kubectx +++ b/kubectx @@ -29,9 +29,28 @@ USAGE: EOF } +function current_context { + kubectl config view -o=jsonpath='{.current-context}' +} + +function get_contexts { + kubectl config get-contexts | awk '{print $2}' | tail -n +2 +} + function list_contexts { set -u pipefail - kubectl config get-contexts | awk '{print $2}' | tail -n +2 + local cur="$(current_context)" + local bold=$(tput bold) + local yellow=$(tput setaf 3) + local normal=$(tput sgr0) + + for c in $(get_contexts); do + if [[ "$c" = "$cur" ]]; then + echo "${bold}${yellow}$c${normal}" + else + echo "$c" + fi + done } function read_context {