From 4520d3f54bd45842764223460f2bbd645ab1edd6 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Tue, 10 Apr 2018 21:45:28 -0700 Subject: [PATCH] Do not print colors if stdout isn't tty This is previously offered in #18, #22, and #27 and I previously rejected these PRs. My rationale was to prevent scripting around kubectx as it is meant to be used as an interactive tool. But clearly that will be a problem, when you're doing operations like: kubectx -d $(kubectx) which I proposed in #39. Plus this change is harmless. I think this implementation does a better check than the previous ones. Signed-off-by: Ahmet Alp Balkan --- kubectx | 2 +- kubens | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kubectx b/kubectx index 3da322f..67714aa 100755 --- a/kubectx +++ b/kubectx @@ -59,7 +59,7 @@ list_contexts() { normal=$(tput sgr0) for c in $(get_contexts); do - if [[ "${c}" = "${cur}" ]]; then + if [[ -t 1 && "${c}" = "${cur}" ]]; then echo "${darkbg}${yellow}${c}${normal}" else echo "${c}" diff --git a/kubens b/kubens index 93fbb86..28affc4 100755 --- a/kubens +++ b/kubens @@ -113,7 +113,7 @@ list_namespaces() { cur="$(current_namespace)" ns_list=$(get_namespaces) for c in $ns_list; do - if [[ "${c}" = "${cur}" ]]; then + if [[ -t 1 && "${c}" = "${cur}" ]]; then echo "${darkbg}${yellow}${c}${normal}" else echo "${c}"