forgit icon indicating copy to clipboard operation
forgit copied to clipboard

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

Open cjappl opened this issue 1 year ago • 7 comments

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.

cjappl avatar Mar 18 '24 21:03 cjappl

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

ccoVeille avatar May 07 '24 19:05 ccoVeille

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.

sandr01d avatar Jun 17 '24 19:06 sandr01d

Thanks for your reply. It's clearer.

I like the implementation you made

ccoVeille avatar Jun 17 '24 19:06 ccoVeille

@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.

carlfriedrich avatar Jun 25 '24 17:06 carlfriedrich

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.

sandr01d avatar Jun 25 '24 18:06 sandr01d

@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

ccoVeille avatar Jun 26 '24 05:06 ccoVeille

Also, you could mention delta as a recommended dependency

We already mention it as an optional dependency on the README here and it's set as an optional dependency in the AUR package as well.

And the code react to delta availability.

We automatically use delta when it's set as the respective pager in the git config (or set in the FORGIT_BLAME_PAGER environment variable). I don't see the need to add extra code here, since this can easily be configured. Let me know if any of you have a different opinion on this, otherwise I'm going to close this issue sometime soon.

sandr01d avatar Aug 14 '24 20:08 sandr01d