fixup colors
authorIan Kelling <ian@iankelling.org>
Tue, 8 Mar 2022 03:29:03 +0000 (22:29 -0500)
committerIan Kelling <ian@iankelling.org>
Tue, 8 Mar 2022 03:29:03 +0000 (22:29 -0500)
brc

diff --git a/brc b/brc
index a51d7db6c7b6dcf8788106758c1dc8890caf64b1..d0c0f8d655be4f9e68fceff05538cae58940b960 100644 (file)
--- a/brc
+++ b/brc
@@ -141,6 +141,7 @@ if ! type -p stty >/dev/null; then
 fi
 
 
+use_color=false
 if [[ $- == *i* ]]; then
   # for readline-complete.el
   if [[ $LC_INSIDE_EMACS ]]; then
@@ -151,6 +152,11 @@ if [[ $- == *i* ]]; then
     bind '"\C-i": self-insert'
   else
 
+
+    if [[ $TERM != dumb ]] && test -t 1; then
+      use_color=true
+    fi
+
     if [[ $KONSOLE_PROFILE_NAME ]]; then
       TERM=xterm-256color
     fi
@@ -1884,24 +1890,7 @@ s/^\Wcapability: (.*)/\1/;Ta;h;b
 # * misc stuff
 
 
-# temporary variables to test colorization
-# some copied from gentoo /etc/bash/bashrc,
-use_color=false
-# dircolors --print-database uses its own built-in database
-# instead of using /etc/DIR_COLORS.  Try to use the external file
-# first to take advantage of user additions.
-safe_term=${TERM//[^[:alnum:]]/?}   # sanitize TERM
-match_lhs=""
-[[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
-[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
-[[ -z ${match_lhs}    ]] \
-  && type -P dircolors >/dev/null \
-  && match_lhs=$(dircolors --print-database)
-# test if our $TERM is in the TERM values in dircolor
-[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
-
-
-if ${use_color} && [[ $- == *i* ]]; then
+if $use_color; then
 
   term_bold="$(tput bold)"
   term_red="$(tput setaf 1)"
@@ -1965,10 +1954,7 @@ if [[ $- == *i* ]]; then
       0) ps_color="$term_purple"
          ps_char='\$'
          ;;
-      1) ps_color="$term_green"
-         ps_char="$return \\$"
-         ;;
-      *) ps_color="$term_yellow"
+      *) ps_color="$term_green"
          ps_char="$return \\$"
          ;;
     esac
@@ -1991,12 +1977,12 @@ if [[ $- == *i* ]]; then
     # but then we get an email and log of lots of failed sudo commands.
     # We could turn those off, but seems better not to.
     if [[ $EUID != 0 ]] && [[ $DID_SUDO ]]; then
-      ps_char="SUDO $ps_char"
+      psudo="\[$term_bold$term_red\]s\[$term_nocolor\] "
     fi
     if [[ ! $HISTFILE ]]; then
       ps_char="NOHIST $ps_char"
     fi
-    PS1="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$term_nocolor\] "
+    PS1="${PS1%"${PS1#*[wW]}"} $psudo\[$ps_color\]$ps_char\[$term_nocolor\] "
 
     # set titlebar. instead, using more advanced
     # titelbar below