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.
I also created a patched version of this based on the gist fork https://gist.github.com/skanev/0eeb943e3111a1df55fd of this fix some missing nil checks that caused exceptions. https://github.com/TysonAndre/git-diff-syntax-highlight
Other notable changes:
I patched coderay's constants to use a custom color scheme in https://github.com/TysonAndre/git-diff-syntax-highlight/blob/master/vim.rb . This may be of interest if the default color scheme is hard to read, or you want the color scheme to match other tools you use.