Solved In csh, how would I switch prompt color depending on background?

I tried looking in how to load a separate configuration file, so I could use one for a dark background, and another for a white background for the same user.

I want a dark prompt for xterm, which has a white background, and a yellow prompt for the dark tinted transparent rxvt-unicode background. The rest of my colors are fine.

~/.tcshrc
Code:
set prompt = "%{\033[1;33m%}%~ %#%{\033[0m%} "
set prompt = "%{\033[1;34m%}%~ %#%{\033[0m%} "
Those are the two colors for the prompt yellow and dark blue. I rather have yellow for the black background, than a color that fits both backgrounds. Could I use an if/then statement in the configuration file depending on the terminal?
 
Sure, like this:
Code:
if ( ... something ... ) then
    set prompt = ... one thing ...
else
    set prompt = ... other thing ...
endif
The question is: What will you test on? Try looking at the terminal type $TERM, which might be slightly different for xterm versus rxvt, and then write the test like "if ( $TERM == "xterm-foo" )". Note that there have to be spaces between things in the if statement; tcsh is very picky about that.

In reality, doing it this way is a very fragile hack: it happens to work because you have configured xterm and rxvt this way. The "right" solution would be for your tcshrc file to explicitly ask the terminal emulator "what is your background color" and act accordingly. Unfortunately, I don't know a way to do that; there is no ANSI escape sequence that one can use to ask a terminal emulator that particular question. There are other escape sequences that work, for example "how big is your screen", but I don't know one for colors.
 
echo $TERM
Code:
        if ( $TERM == "rxvt" ) then
                set prompt = "%{\033[1;33m%}%~ %#%{\033[0m%} "
        else
                set prompt = "%{\033[1;34m%}%~ %#%{\033[0m%} "
        endif
 
Back
Top