From 8041037eda433bcc7a0ee22e795b7ffefe8faf23 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Thu, 16 Jul 2026 16:52:16 -0700 Subject: [PATCH] Properly handle terminals which do not have 256 colors. --- rc_shared.sh | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/rc_shared.sh b/rc_shared.sh index 951a83f..ac31d97 100644 --- a/rc_shared.sh +++ b/rc_shared.sh @@ -9,15 +9,39 @@ export PATH="$PATH:~/bin-shared:~/.bin-shared" # PS1 Colors # -export PURPLE="`tput setaf 55`" -export ORANGE="`tput setaf 208`" -export GREEN="`tput setaf 34`" +colors=`tput colors` +if (( colors >= 256 )); then + export PURPLE="`tput setaf 55`" + export ORANGE="`tput setaf 208`" + export GREEN="`tput setaf 34`" -export RED="`tput setaf 196`" -export SCARLET="`tput setaf 160`" -export YELLOW="`tput setaf 226`" + export RED="`tput setaf 196`" + export SCARLET="`tput setaf 160`" + export YELLOW="`tput setaf 226`" + + export GRAY="`tput setaf 243`" +elif (( colors == 16 )); then + export PURPLE="`tput setaf 13`" + export ORANGE="`tput setaf 11`" + export GREEN="`tput setaf 02`" + + export RED="`tput setaf 09`" + export SCARLET="`tput setaf 01`" + export YELLOW="`tput setaf 11`" + + export GRAY="`tput setaf 08`" +else + export PURPLE="`tput setaf 05`" + export ORANGE="`tput setaf 03`" + export GREEN="`tput setaf 02`" + + export RED="`tput setaf 05`" + export SCARLET="`tput setaf 01`" + export YELLOW="`tput setaf 03`" + + export GRAY="`tput setaf 07`" +fi -export GRAY="`tput setaf 243`" export RESET="`tput sgr0`" export BOLD="`tput bold`" @@ -862,8 +886,10 @@ function git-check { # TBD: Move this to a different section? function check-colors { min=0 - max=255 + max=256 unset i + echo "Current terminal supports '`tput colors`' colors." + echo "Displaying examples..." for (( i = min; i <= max; i++ )); do tput setaf $i printf "%03d" "$i"