When running git status -sb
I see:
I want to watch
(from procps-ng 3.3.3) a repository. The --color
option is supposed to keep colours.
Interestingly, it works with ls
:
$ watch --color "ls --color"
Showing:
However for git
the colours disappear:
$ watch --color "git status -sb"
So, why does watch
show colours from ls
but not from git
output?
git
uses a configuration value to determine whether to show coloured output or not.For example:
This sets the colour setting to
auto
globally. Inauto
mode, git will determine whether it's a real terminal before sending colour codes, as Oli suggested.You can force this global value to
always
, however a better idea may be to apply it to a particular command:Putting it all together:
The following statements are true:
watch
runs the command in a new shell,sh
..bashrc
aliasesls
asls --color=auto
to enable colours.sh
doesn't inherit or usebash
aliases.So when
watch
runsls
, it's not asking for colours, it's just running the plain old version. You can circumvent this but—as aditya points out—you also need to enable colours onwatch
for it to process them properly.A working example for
ls
is:If you don't pass
--color
to watch, you'll see a bunch of ugly colour codes inline.ls --color
is interpreted asls --color=always
.ls --color=auto
does not print colour in watch. This suggests that it's inferring colour support from the terminal itself.For more on the reason why, we can test if the watch shell thinks its a real terminal:
I suspect that some applications are looking at that (or similar) to tell if they should turn on colours or not.
It works if
git
(--color
) andwatch
(-c
) are told to use colors: