cgit syntax highlighting
NB: since writing this I have migrated all my code to Github and stopped using cgit. Therefore many of the links no longer work
For the last few months I've been using git for my version control system. It's better than CVS because it can handle offline commits. So if I'm using my laptop on a train, I can still use version control without having to have a notwork connection.
And to give a pretty web front-end to it for other people to read code without having to check it out of the repository, I use cgit, which I mostly chose because it's a dead simple CGI and not a huge fancy application.
One problem with cgit is that by default it doesn't do code highlighting. But it has the ability to run blobs of code through any filter you care to name before displaying them, so to get something nice like this all you need to do is write a highlighter and add a single line to your cgitrc:
source-filter=/web/www.cantrell.org.uk/cgit/highlighter
My highlighter program is this:
1 #!/usr/local/bin/perl
2
3 use warnings;
4 use strict;
5
6 my $file = shift;
7
8 if($file =~ /\.(p[ml]|t)$/i) {
9 system "/usr/local/bin/perltidy -html -st -ntoc -npod -pre -nss -nnn"
10 } else {
11 system "cat -n";
12 }