CGIT is a free and simple webby front-end to let people browse your git repository without having to check out a copy of your code to their machine. I chose to use it because it's dead simple - build a single CGI, put it somewhere that your web sewer can read it, and write a simple config file. Job done, no complicated libraries to build, it Just Works. And because it's written in C, it's fast and consumes few resources.

It doesn't do syntax highlighting when displaying code. But it does have a facility to run any blobs of code through a filter before displaying them, so you can easily put your own filter in place to do the highlighting for you. To configure it, simply put something like this:

source-filter=/web/www.cantrell.org.uk/cgit/highlighter

in your /etc/cgitrc. And the script reads:

#!/usr/local/bin/perl use warnings; use strict; my $file = shift; if($file =~ /\.(p[ml]|t)$/i) { system "/usr/local/bin/perltidy -html -st -ntoc -npod -pre -nss -n +nn" } else { system "cat -n"; }

Replies are listed 'Best First'.
Re: Syntax highlighting in CGIT
by doug (Pilgrim) on Aug 17, 2009 at 17:31 UTC

    Please don't just look at file extensions because goodness knows that most of my perl scripts don't have a suffix. The libraries have .pm of course, but nothing for the main program. Use the program file to check for perl.

    Lookup magic if you're unfamiliar with examining the contents of a file to figure out what type of file it is.

    - doug
      File extensions do a good enough job for my repo, which is the only one that matters to me. Feel free to change the code if you use it.
Re: Syntax highlighting in CGIT
by Bloodnok (Vicar) on Aug 17, 2009 at 13:17 UTC
    .oO(web sewer - DrHyde must be using Exploder on Windoze :-D )

    Interesting post nonetheless.

    A user level that continues to overstate my experience :-))
Re: Syntax highlighting in CGIT
by bduggan (Pilgrim) on Aug 21, 2009 at 18:06 UTC
    Very nice, thanks. Didn't know about the new "source-filter" option. Now I can stop using prettify, which I had set up like this:
    cgitrc : footer=/home/bduggan/local/www/cgit_footer
    which contains :
    <link type="text/css" rel="stylesheet" href="/prettify/src/prettify.cs +s" /> <script type="text/javascript" src="/prettify/src/prettify.js"></scrip +t> <script type="text/javascript"> window.onload=prettyPrint; </script>