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.
Let's move the discussion here. Here is a fork with syntax highlighting for all of the code, not only the added and removed parts: https://gist.github.com/valo/4a8f4db480c220de215d
The problem is that is becomes difficult to see the added and the remove parts if the syntax highlighting is using red and green.
@skanev, yes, probably a gradient to gray may help. I will experiment with this...