Tuesday, October 12, 2010

Colorizing and autopaging svn diffs and other commands

I can't remember the last time I jacked off to black and white pornography.

Can you?

OF COURSE YOU CANT! Color is fucking awesome! No one yanks their crank to black and white shit anymore.

Once you've tasted color, you can never go back.

This brings us to the subject of version control. Over the last few years I've been spoiled by git, but have recently switched jobs and been using svn again. Using git has taught me to actually care what I'm committing — as opposed to just creating one giant commit at the end of the day — which has meant I've been looking at lots of diffs.

Git gives you lovely colorized, paged diffs that frequently stiffen the schlong. While svn, on the other hand, still gives you the same uncolored, unpaged horse shit as it did several years ago! I can't fucking believe the meat puppets at svn haven't gotten their asses into gear and stolen some basic UI ideas from the competition. WTF guys?!

Here's how you enable color for everything in git:

git config --global color.ui always

There are more granular options if you want them, but fuck that, color is awesome!

Svn has no such option. So I, like many others, have been forced to hack the mainframe to get color. Check my hacks:

This script defines a function called "svn" that hijacks calls to the svn program and essentially rewrites some of the commands. For example, this command:

svn diff -r1:7 foo

would get rewritten to:

svn diff -r1:7 foo | colordiff | sed -e 's/\r//g' | less -RF

Another example:

svn log foo

would get rewritten to:

svn log foo | less -F

Notice that I'm still interacting with svn via the same command set, and am not training myself away from the existing commands. Hopefully this will prevent me from losing the plot and ripping off cocks when forced to use svn on a machine that doesn't have my hacks.


  1. Hi!

    Thanks for dropping that comment in my sed-to-color post, I will use it next time I use sed for something (I'm not using gcal ATM, but probably will do it any time soon, it is just too practical now I have DropBox ;)

    I loved this post, btw, in particular your 'love for colour'. Still smiling :D And the Tentacles... Terrific. I usually use RCS for personal one-computer projects, though (small, simple and old as it can get).


    Latest in my blog: 33 Best Posts I Have Read This August, 2010

  2. I always like to use tr instead of sed for deleting characters. Not that it makes much difference, but it's definitely faster. WORDS.CR is a file with 197138 lines ending in '\r'.

    ~$time sed -e 's/\r//g' < WORDS.CR > /dev/null

    real 0m0.087s
    user 0m0.080s
    sys 0m0.008s

    ~$time tr -d '\r' < WORDS.CR > /dev/null

    real 0m0.003s
    user 0m0.004s
    sys 0m0.000s

  3. After loading your function, if you redirect the output of the svn command, the output gets corrupted. To prevent it, you sould change add this to the beginning of the svn function:

    if [ $# -lt 1 -o ! -t 1 ]; then
    command svn "$@"