less itself isn't capable of doing syntax highlighting, according to this thread. However, git diff nicely shows colored output in less, its default pager. When I redirect the output of git diff into a file, no color escape sequences are visible. Does git diff know where it's being sent, and formats the output accordingly? How would one do that?I just noticed that git colors the diff output (e.g. git diff), however, it doesn't know how to syntax highlighting in general. e.g.git show 415fec6:log.texdoesn't enable any TeX-like syntax. Reading the git sources, I found the following hintsin diff.h:int use_color;I was previously referring to syntax highlighting, but that was not correct. What I mean is output coloring, see e.g.
Git pager is less, but what is causing the output coloring?
colors;git;diff;pager;colordiff
Git uses isatty() to check whether stdout is a tty: this is used to see if a pager must be used (pager.c) as well as colors (color.c).