November 19, 2008

Doing a diff without touching the command line

Author: Ben Martin

With diff-ext, GNOME users can compare and merge files from within Nautilus. If, instead, you use KDE 3, try out kdiff-ext from the same site, which works with Konqueror. Each utility handles paths to files and directories and invokes an external diff tool to perform the grunt work. With diff-ext you can easily compare two files with different names, from different directories, or whole directory trees.

Among the major Linux distributions, the only package I could find was gdiff-ext for Ubuntu Intrepid. I'll build the program from source using version 0.3 of gdiff-ext on a 64-bit Fedora 9 machine. At the time of writing the downloads page erroneously listed 0.2.4 as the latest version of gdiff-ext. You might like to click on the "Older versions" link at the bottom of the project's page to investigate what releases exist for download to verify the latest version.

To build gdiff-ext you'll need to have nautilus-devel installed on Fedora 9 or openSUSE 11. On Intrepid you'll want libnautilus-extension-dev installed. Then run:

$ tar xjvf /FromWeb/gdiff-ext-0.3.tar.bz2
$ cd ./gdiff-ext-*
$ ./configure
$ make -k
make[3]: Entering directory `/home/ben/gdiff-ext-0.3/diff-ext/src'
-fPIC -DPIC -o .libs/main.o
main.c:16:25: error: gconf/gconf.h: No such file or directory
main.c:17:32: error: gconf/gconf-client.h: No such file or directory
main.c:18:41: error: libgnomevfs/gnome-vfs-utils.h: No such file or directory

It is a shame that the gdiff-ext sources have become a little convoluted to build from, but it's nothing that a new release couldn't fairly easily clean up. To get around what appears to be an issue finding your GConf development files, you can try exporting some additional GNOME libraries into your CFLAGS, as shown below.

$ export CFLAGS=`pkg-config gnome-vfs-2.0 eel-2.0 --cflags`
$ ./configure
$ make
make[3]: Entering directory `/home/ben/gdiff-ext-0.3/setup/src'
main.c:17:37: error: eel/eel-mime-extensions.h: No such file or directory
main.c: In function 'main':
main.c:116: warning: initialization makes pointer from integer without a cast

To get around the above compile issue in setup/src involving the eel library, copy eel-mime-extensions.c/eel-mime-extensions.h from eel-2.20.0 to setup/src and edit main.c to include the header and source file from the current directory. The eel-mime-extensions files were removed from libeel in October 2007.

$ vi setup/src/main.c
#include <libgnomevfs/gnome-vfs-mime-info.h>
#include "eel-mime-extensions.h"
#include "eel-mime-extensions.c"

$ make
$ sudo make install

Once everything completes successfully you will have to restart Nautilus for it to notice gdiff-ext. If your GNOME environment is set up to respawn Nautilus, you can send kill all your Nautilus processes and have it respawned. The last step is to start gdiff-ext-setup to make sure that your favourite diff program is run by gdiff-ext.

$ killall -15 nautilus
$ gdiff-ext-setup

Now you should be able to select two files in a directory in Nautilus, right-click to bring up the context menu, and notice a Compare entry toward the bottom of the menu. Selecting Compare will run your preferred diff utility on these files as shown in the adjacent screenshot.

If you have only a single file highlighted and bring up the context menu you will see "Compare later" in the context menu. Selecting that option places the path of the selected file onto a stack. The next time you select a single file you will see both "Compare later" and "Compare to '/.../first-file'" in the context menu.

If you select two files, you will be able to compare those two like before, but also have the option to run a three-way comparison with a file from the "Compare later" stack. Although I mention a compare stack, currently gdiff-ext only lets you compare with the very last thing you added to the "Compare later" stack.

If you select two directories and choose Compare, then both directories are passed to your nominated diff tool. For example, using Meld as I did during testing a recursive diff between the two directories is shown.

The project provides documentation for gdiff-ext but nothing for kdiff-ext.

Having diff-ext available in your file manager gives you great flexibility in running diff on files in different locations. If you have a large display with many file manager windows open at once, you might actually be able to start a diff quicker with the mouse than in a terminal window.


  • Tools & Utilities
  • Desktop Software
Click Here!