Question
I want git
to automatically colorize the output when it is going to a device that can handle color and not colorize it when it cannot. How would one do this?
Background
I sometimes develop code for older machines using the machines themselves. Some of them can handle ANSI color and some of them cannot. On UNIX systems we used to have a database called TERMINFO which listed capabilities of each terminal. It was easy to tell if a terminal supported color by checking the colors
capability. If it was -1, then a program should definitely not send ANSI color sequences.
$ tput colors
-1
Ideally, git would use TERMINFO to automatically detect if ANSI color sequences are appropriate. But it doesn't and checks only isatty()
. I suspect it is not a high priority for the git developers to add TERMINFO support, so I'm looking for any workaround that will give the same functionality.
I already know how to disable git color using git config
and that is not what I'm asking. I want it to only be disabled when I log in from a terminal that does not support ANSI colors, such as a Digital VT340.
I also have already seen the GIT_CONFIG_PARAMETERS="'color.ui=never'"
environment variable, but according to @bk2204 and @torek, that variable is going to disappear soon.