-
-
Save hb/3332269 to your computer and use it in GitHub Desktop.
Nautilus script to "just diff the right thing"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from subprocess import call | |
from os import environ | |
# selected files and current locations of the panes | |
cp_selection = environ["NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"].split() | |
op_selection = environ["NAUTILUS_SCRIPT_NEXT_PANE_SELECTED_FILE_PATHS"].split() | |
cp_location = environ["NAUTILUS_SCRIPT_CURRENT_URI"][7:] | |
op_location = environ["NAUTILUS_SCRIPT_NEXT_PANE_CURRENT_URI"][7:] | |
diff_args = [] | |
# if two files are selected in current pane -> diff them | |
if len(cp_selection) == 2: | |
diff_args = cp_selection | |
# else if one file is selected on each pane -> diff those | |
elif len(cp_selection) == 1 and len(op_selection) == 1: | |
diff_args = [cp_selection[0], op_selection[0]] | |
# two panes, no files selected -> diff the two directories | |
elif len(cp_selection) == 0 and len(op_selection) == 0: | |
diff_args = [cp_location, op_location] | |
# assemble and call command | |
if diff_args: | |
cmd = ["meld"] | |
cmd.extend(diff_args) | |
else: | |
cmd = ["zenity", "--error", "--text=No suitable diff mode for selection."] | |
call(cmd) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment