dandavison / delta

A syntax-highlighting pager for git, diff, grep, and blame output
https://dandavison.github.io/delta/
MIT License
22.74k stars 380 forks source link

🚀 Enable using delta in git when output is piped (`git diff | cat`) #1583

Closed infokiller closed 9 months ago

infokiller commented 9 months ago

Hi,

I noticed that git uses its internal diff formatting instead of delta when piping its output, for example the following command doesn't show output from delta:

git -c interactive.diffFilter='delta --color-only --pager=/bin/cat' -c core.pager='delta --pager=/bin/cat' diff --color=always 'main^..main' | head

I suspect this is related to https://github.com/dandavison/delta/issues/799#issuecomment-1077865831, i.e. using delta via GIT_EXTERNAL_DIFF or diff.external in the config would solve it. However, that requires delta to support being invoked with the args path old-file old-hex old-mode new-file new-hex new-mode.

dandavison commented 9 months ago

Hi @infokiller, nice to hear from you. I view it as desired behavior, not a bug, that git does not use delta when output is going to a pipe: IMO delta's output is for humans to read, not for machines to parse, so there are few scenarios when one wants delta's output to go to a pipe/file. Do you have such a scenario?

As you say, the way this (IMO desired) behavior is achieved is that git itself doesn't invoke its pager when output is not a tty (because the git authors view the pager output as for human eyes, not machines). That means also that there's a simple solution for the cases when one does want delta's output to go to a pipe: pipe it into delta explicitly:

git diff | delta | head

So I'm definitely happy to hear ideas about GIT_EXTERNAL_DIFF, but I'm going to close this since I don't think delta should change anything regarding this behavior. But do feel free to reopen.

dandavison commented 9 months ago

That said there is something fairly esoteric in one of the end-to-end tests that does what you're asking for I think!

https://github.com/dandavison/delta/blob/59b4a2ead4b621c5576ed66bdc2bf3f53f041489/tests/test_navigate_less_history_file#L32-L34?

infokiller commented 9 months ago

Hi @dandavison great to talk to you again and thanks for the quick response! My use case was using it for fzf previews. Indeed, both of your suggestions work fine for this use case, thanks!