wfxr / forgit

:zzz: A utility tool powered by fzf for using git interactively.
MIT License
4.32k stars 136 forks source link

`gbl` should have nice syntax coloring (or optionally use GIT_PAGER or `bat`?) #370

Open cjappl opened 3 months ago

cjappl commented 3 months ago

Currently if you use gbl you get a rather dull monochrome blame:

Screenshot 2024-03-18 at 2 52 36 PM

It would be nice if we could put this through a nicer pager, or add syntax highlighting somehow.

ccoVeille commented 1 month ago

isn't it already possible ?

FORGIT_BLAME_PAGER='bat --color=always -l log' git forgit blame

image

FORGIT_BLAME_PAGER='bat --color=always -l gitlog' git forgit blame

image

sandr01d commented 1 week ago

isn't it already possible ?

FORGIT_BLAME_PAGER='bat --color=always -l log' git forgit blame

@ccoVeille this would color everything using the same syntax (log), but ideally we would have syntax highlighting based on the file.

bat (which we already use for gbl) supports syntax highlighting based on the file extension. We currently do not pass the file name to bat and only pipe the content of the file when using gbl. We could use the --file-name parameter to make bat use the correct syntax. I did a quick and dirty implementation to see what the results would look like. Some files look fine, e.g.

image

For others, the annotations get colored, since bat isn't aware of them.

image

This is especially bad when using --color-by-age or --color-lines since it makes the highlights in the annotations less visible IMO:

image

Would be interested what others think, but I personally would value visible highlights from --color-lines more than syntax highlighting in the context of git blame. delta has special highlighting for git blame. This can already be used when configuring delta as pager.

ccoVeille commented 1 week ago

Thanks for your reply. It's clearer.

I like the implementation you made

carlfriedrich commented 4 days ago

@sandr01d I would also value the --color-lines more than syntax highlighting of the file.

However, if delta supports git blame highlighting (which is cool, wasn't aware of that!), then we have a solution, don't we? We could add delta as a soft dependency, just like we do with bat. How about that?

Personally, I am using diff-so-fancy as a pager because I like its diff presentation more than delta's. That's personal preference, though, and I would actually like using delta for gbl if it does something useful there.

sandr01d commented 4 days ago

I agree with you @carlfriedrich. The AUR package already has delta as an optional dependency and we also list it on our README. The only thing to look out for with delta and blame is https://github.com/dandavison/delta/issues/1278, but this can be worked around with FORGIT_BLAME_GIT_OPTS="--date=iso8601" for now.

ccoVeille commented 4 days ago

@carlfriedrich it's indeed a good solution.

Also, you could mention delta as a recommended dependency. And the code react to delta availability.

But it might be what you were thinking about