I have been using Nemo as my file browser for almost a year now.. Since nautilus lost the most used features and started assuming things that I never intended to…

Recently, I had to do a comparison of a few text files and had to go to console and open the diff viewer.. Thought, what if nemo had this ability in itself (something like in the right click menu).. Started searching for it and found a link that talked about how this can be accomplished.

Abstract:

You need to create the following files (along with their contents) in .local/share/nemo/actions under your home directory. (System wide location : /usr/share/nemo/actionsI haven’t tried it yet though.. But, it should work.)

nemo_action files are the files that creates menu entries in the pop-up dialog that comes up when you right click. These files are read by nemo whenever you right click. The syntax is similar to a .desktop file. You can invoke a script from these nemo_action files that does your job. If you want to change the script, feel free to do so. And to verify your changes, all you have to do it save the changes and right click on nemo :).. (I know how happy a software engineer will be for not having to wait for testing their changes)

You can have a look at /usr/share/nemo/actions/sample.nemo_action and /usr/share/nemo/actions/myaction.py. These files have detailed information on what each field in the action files indicates. Really simple and useful 🙂

We are going to add options to:

  • Select for comparison (We are selecting a file that we need to compare with)
  • Compare with selected file (Compare with the file selected in previous step. This option will be visible only when a file has been already selected for comparison.)

How are are going to add those options?

Simple. Do what we have been doing all these years (In short, Copy Paste) the exact content given below as it is. It will work 🙂

Lets get into action:

$HOME/.local/share/nemo/actions/compare-save-for-later.nemo_action

[Nemo Action]
Active=true
Name=Compare later
Comment=Save file for comparison later.
Exec=<compare.sh save %F>
Icon-Name=meld
Selection=S
Extensions=any

$HOME/.local/share/nemo/actions/compare-with-saved.nemo_action

[Nemo Action]
Active=true
Name=Compare with saved element
Comment=Compare %F saved file or directory.
Exec=<compare.sh compare %F>
Icon-Name=meld
Selection=S
Extensions=any

$HOME/.local/share/nemo/actions/compare.sh

#!/bin/bash
savedfile=/tmp/compare-save-for-later.$USER
comparator=/usr/bin/meld

if [ -L $0 ] ; then
DIR=$(dirname $(readlink -f $0)) ;
else
DIR=$(dirname $0) ;
fi

if [ “$1” == “save” ]; then
echo “$2” > “$savedfile”
chmod 700 $savedfile
else
“$comparator” $(cat “$savedfile”) “$2” &
mv $DIR/compare-with-saved.nemo_action $DIR/compare-with-saved.nemo_action1
rm -f $savedfile
fi

if [ -f $savedfile ]; then
mv $DIR/compare-with-saved.nemo_action1 $DIR/compare-with-saved.nemo_action
fi

NOTE:

If you think your file names may contain spaces in them, then you can add Quote=double to the nemo_action files mentioned above. Nemo encapsulates each path in double quotes and passes it to the diff viewer.

Advertisements