From: Ian Kelling Date: Tue, 8 Mar 2022 03:29:03 +0000 (-0500) Subject: fixup colors X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=commitdiff_plain;h=6cb2fbb730b7ea2d95618bace310ef40c43e51a2 fixup colors --- diff --git a/brc b/brc index a51d7db..d0c0f8d 100644 --- 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}$(/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