Skip to content

Instantly share code, notes, and snippets.

@ozh
Created April 28, 2026 17:15
Show Gist options
  • Select an option

  • Save ozh/32024d7ba1dc518aa42d04d3ca250d71 to your computer and use it in GitHub Desktop.

Select an option

Save ozh/32024d7ba1dc518aa42d04d3ca250d71 to your computer and use it in GitHub Desktop.
Nemo action: Git diff with Meld

Nemo action: Git diff with Meld

Right-click any file, folder, or the background of a Nemo window inside a git repository to open a diff in Meld.

image
  • Right-click a file - diff that file
  • Right-click a folder icon - diff the contents of that folder
  • Right-click the empty area of a Nemo window - diff the contents of the current directory

If the file or directory has no changes, a popup tells you so. If the path is not inside a git repository, an error popup is shown. Both popups appear in front of the Nemo window.

Requirements

  • Meld
  • xdotool (used to bring the popup in front of Nemo)
  • zenity (usually installed by default on GNOME/Cinnamon)
  • git

On Debian/Ubuntu/Mint:

sudo apt install meld xdotool zenity

Installation

1. Create the actions directory if it doesn't exist:

mkdir -p ~/.local/share/nemo/actions

2. Copy the script and make it executable:

cp git-meld-diff.sh ~/.local/share/nemo/actions/
chmod +x ~/.local/share/nemo/actions/git-meld-diff.sh

3. Copy the three action files:

cp git-meld-diff-file.nemo_action ~/.local/share/nemo/actions/
cp git-meld-diff-dir.nemo_action  ~/.local/share/nemo/actions/
cp git-meld-diff-bg.nemo_action   ~/.local/share/nemo/actions/

4. Edit the three .nemo_action files:

Replace /home/ozh/ with your own home directory path (full path, not ~/you).

5. Restart Nemo:

nemo -q ; sleep 1 ; nemo &

Files

git-meld-diff.sh

The script shared by all three actions. Handles file, directory, and background cases.

#!/bin/bash
# Open Meld to show git diff for a file or directory

TARGET="${1#file://}"

WINDOWID=$(xdotool getactivewindow 2>/dev/null)

zenity_msg() {
    local type="$1"
    local msg="$2"
    if [ -n "$WINDOWID" ]; then
        zenity --"$type" --text="$msg" --attach="$WINDOWID" 2>/dev/null
    else
        zenity --"$type" --text="$msg" 2>/dev/null
    fi
}

if [ -f "$TARGET" ]; then
    DIR=$(dirname "$TARGET")
else
    DIR="$TARGET"
fi

GIT_ROOT=$(git -C "$DIR" rev-parse --show-toplevel 2>/dev/null)

if [ -z "$GIT_ROOT" ]; then
    zenity_msg "error" "Not a git repository."
    exit 1
fi

if [ -f "$TARGET" ]; then
    # Single file: diff that file
    if git -C "$GIT_ROOT" diff --quiet -- "$TARGET" && \
       git -C "$GIT_ROOT" diff --quiet --cached -- "$TARGET"; then
        zenity_msg "info" "No changes in this file."
        exit 0
    fi
    meld "$TARGET" &
else
    # Directory: diff scoped to that directory
    if git -C "$GIT_ROOT" diff --quiet -- "$DIR" && \
       git -C "$GIT_ROOT" diff --quiet --cached -- "$DIR"; then
        zenity_msg "info" "No changes in this directory."
        exit 0
    fi
    meld "$DIR" &
fi

git-meld-diff-file.nemo_action

Appears when right-clicking a file.

[Nemo Action]
Name=Git diff with Meld
Comment=Show uncommitted changes in Meld
Exec=/home/ozh/.local/share/nemo/actions/git-meld-diff.sh %F
Icon-Name=meld
Selection=S
Mimetypes=text/plain;text/html;text/css;text/xml;text/x-script.python;text/x-php;text/x-shellscript;text/x-markdown;application/javascript;application/json;application/xml;application/x-php;application/x-shellscript;

git-meld-diff-dir.nemo_action

Appears when right-clicking a folder icon.

[Nemo Action]
Name=Git diff with Meld
Comment=Show uncommitted changes in Meld
Exec=/home/ozh/.local/share/nemo/actions/git-meld-diff.sh %F
Icon-Name=meld
Selection=S
Mimetypes=inode/directory;

git-meld-diff-bg.nemo_action

Appears when right-clicking the empty background of a Nemo window.

[Nemo Action]
Name=Git diff with Meld
Comment=Show uncommitted changes in Meld
Exec=/home/ozh/.local/share/nemo/actions/git-meld-diff.sh %P
Icon-Name=meld
Selection=None
Extensions=any;

Notes

  • The Mimetypes list in the file action covers common dev file types. If a file type you use is missing from the right-click menu, check its mimetype with file --mime-type yourfile and add it to git-meld-diff-file.nemo_action.
  • For directory and background actions, Meld is scoped to the target directory, not the git root, so you only see changes relevant to where you clicked.
  • xdotool captures the active window ID at script start so the popup attaches to Nemo even after focus changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment