0

Is it possible to determine whether git would output colors in the current situation when running a git diff.*.textconv converter?

Example:

git diff with color.ui=auto will output colors iff the output is a terminal. I would like the diff.*.textconv converter to also output colors iff the output is a terminal. I can't check within the converter, since git always redirects the output to a non-terminal.

This may be an X-Y problem; I basically just want the best way to syntax-highlight the source content of git diffs, but not if the output is not going to a terminal.

Max Nanasy
  • 5,871
  • 7
  • 33
  • 38

1 Answers1

0

A half-solution (half because it correctly does not output colors when output is piped, but incorrectly doesn't output colors when --color is specified) is to output color iff $GIT_PAGER_IN_USE is set to true.

Max Nanasy
  • 5,871
  • 7
  • 33
  • 38