#!/bin/sh
#
# c2014 by Paul Sherman http://www.pcbypaul.com 
# just a teeny utility that uses zenity dialogs and diff and diffh
# to output a nice html-ified difff.
#
# make sure we have the required programs to run the script ###########################
ret=`which diffh 2>/dev/null`
if [ ! $ret ]; then
	zenity --error --title="An Error Occurred" --text="the program diffh is required, but not installed."
	exit 0
fi
ret=`which diff 2>/dev/null`
if [ ! $ret ]; then
	zenity --error --title="An Error Occurred" --text="the program diff is required, but not installed."
	exit 0
fi
ret=`which zenity 2>/dev/null`
if [ ! $ret ]; then
	zenity --error --title="An Error Occurred" --text="the program zenity is required, but not installed."
	exit 0
fi
# Check if we are running from a file (.desktop)...
# If we were passed a filename, use it as the first file to compare.
# Else we pull a file from a dialog.
if [ -f "$1" ]; then
	file1="$1"
else
	file1="$(zenity --window-icon=/usr/share/pixmaps/diff.png --file-selection --title="Select first file to compare  (you can drag and drop)")"
fi
if [ ! "$file1" ];then
	exit 0
fi
# Get the second file to compare.
file2="$(zenity --window-icon=/usr/share/pixmaps/diff.png --file-selection --title="Select second file to compare  (you can drag and drop)" )"
if [ ! "$file2" ];then
	exit 0
fi
# then run diff, pipe it to diffh, then show in browser.
diff -u $file1 $file2 | diffh > htmldiff.html 2>/dev/null
xdg-open htmldiff.html 2>/dev/null&
exit 0
