At one of my previous jobs, there was a simple script someone shared with me that added coloring to the output of git diffs. After I left that job, I still wanted access to this script, so I spent some time writing a pager that automatically adds syntax highlighting to diffs.

The main challenge with adding syntax highlighting to a git diff is that a diff will contain changes from multiple files, so the highlighter needs to selectively apply different highlighting schemes to the different portions of the diff. Weirdly enough, this is not as easy as it sounds.

In the end, it turns out that I misremembered how the original script works: all it did was color the start of each line green or red based on whether the line was added or removed - what I built was quite the overkill, but I’m still glad I did it.

The main downside to this pager is that it is a bit slow - I wish it could operate as fast as less or more, but I think it would take a re-write in C, Golang or Rust to get to those speeds. However, I’ll leave that job to someone else.