Normally git diff
would color additions green and deletions red. This is cool, but it would be even cooler if it adds syntax highlighting to those lines. This is a git pager that does so.
It parses the diff output and picks up the SHAs of files with additions and deletions. It uses CodeRay to highlight each file and then it extracts the lines that are shown in the diff. It then uses term/ansicolor to make a gradient from the CodeRay color and the diff color (red for deletion, green for addition) and uses it to replace the original.
I tried using rugged
instead of shelling out to git show
– it was faster overall, but it did incur a noticeable start up time.
Check out the image below for a demo.
Added gradient to gray and I think it is much better. The unchanged code stays shaded. It looks to me that the original color is quite changed, but I need to doublecheck on daylight conditions :)