views:

705

answers:

3

I would like to have a if-else loop in .screenrc for the following codes such that it is run if my terminal supports 256 colors. Otherwise, it is not run.

attrcolor b ".I"
# tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm "Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm"
termcapinfo xterm-color "Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm"

How can you make the if-else loop in .screenrc?

A: 

My pseudo-code attempt for .screenrc

[ -e t_Co(256) ] . ColorFile

The same in English

If 256 color support, then source ColorFile.
Masi
+2  A: 

This should already be set by the terminfo database file. In my case my default terminal is xterm. It uses 8 colors which is reflected in vi by using the

:set termcap

command an inspecting the t_Co item which is set to 8. If I change my terminal to another terminal type like gnome-256color which uses 256 colors then vi will show t_Co as equal to 256. I'm not sure why you need to try and set this in your .vimrc file.

Thank you for the piece of information! Then the only problem is to have a if-else loop in .screenrc.
Masi
+1  A: 

I believe something like this should work if you have bash available:

#!/bin/bash
if [ "$TERM" = "xterm-256color" ]; then
    # do stuff for 256
else
    if [ "$TERM" = "xterm" ]; then
        # do stuff for 16
    else
        # do something else entirely
    fi
fi
fiXedd
My terminal application is OS/X's iTerm. I am not sure whether your code works or not, since I have got no evidence that it works.
Masi
Well, you could TRY it.
fiXedd
What happens if you "cat $TERM" on OSX?
fiXedd