Clipboard diff

Posted in:

Ever been refactoring code or HTML templates and wanted to see the difference between two chunks of text, and whether they can be merged in some way? Implementing this in KDE is just too easy. Here is the script you need:

#!/bin/bash

# Show the difference between the last two items
# on the clipboard

TMP1=`mktemp`
TMP2=`mktemp`
dcop klipper klipper getClipboardHistoryItem 0 > $TMP1
dcop klipper klipper getClipboardHistoryItem 1 > $TMP2
kompare $TMP1 $TMP2
rm $TMP1 $TMP2

Save that to a script, then set up a hotkey to it using KHotKeys (I'm using Ctrl+Win+D, 'd' for diff). To use it, copy chunk 1 to the clipboard using Ctrl-C, then chunk 2, then hit Ctrl+Win+D – and you have a beautiful diff for your viewing pleasure.

Screenshot of Kompare showing the difference between 2 items on the clipboard

I just used this to conclude that I have two Django templates that are better off inheriting from a base template and overriding for differences, (rather than each including various snippet templates), especially since one of them has an addition I had forgotten to add to the other. I wrote the script ages ago, but thought someone else might find it useful.

For Windows users, I'm sorry, I imagine it would take you about 3 days to reproduce something like this working reliably. I'm not mocking – I have the pain of using Windows for my day job, and it's like being forced to crawl everywhere on hands and knees after I've learnt to walk.

And don't get me started on software installation. I got myself a python-hosting account the other day, and everything I've tried has just worked. With a bit of help from a web-based tool they have, I had set up a trac/svn app for tracking bugs in about 10 minutes, and added authentication to lock down parts of it in about 20 minutes (trac also has a really nice command line tool for admin, BTW).

At work, on the other hand, using an installer and getting it to work correctly (for things like MS SQL Server, Sharepoint etc), is apparently something of an acquired expertise. Unfortunately for me, 'learning from the school of hard knocks' doesn't seem to have worked yet, so I spent most of this afternoon fighting and losing to various installers.

OK, so I digressed completely and rambled about my frustrations with Windows. Sorry about that.

Comments §

Comments should load when you scroll to here...