Add Linux support

This commit is contained in:
Gleb Mazovetskiy
2018-10-21 14:25:58 +01:00
parent c72412a5fc
commit 670ec172d6
3 changed files with 36 additions and 23 deletions

View File

@ -7,7 +7,7 @@ It can also be run as a direct CLI command for diffing two image files.
Platforms
---------
Only macOS at the moment. Patches welcome!
Only macOS and Linux at the moment. Patches welcome!
Examples
--------
@ -41,9 +41,17 @@ Installation
1. Install exiftool and ImageMagick. (The script will cope with these missing,
but it's not going to be very exciting without them).
```bash
brew install exiftool imagemagick
```
macOS:
```bash
brew install exiftool imagemagick
```
Debian / Ubuntu:
```bash
sudo apt install exiftool imagemagick xdg-open
```
2. Run `./install.sh`, which will configure your global git config for you.
It will tell you what it's done, so it should look something like this:

View File

@ -60,24 +60,24 @@ fi
f1="$1"
f2="$2"
if [ ! -f "$f1" ]
if [[ "$f1" != '/dev/null' ]] && [[ ! -f "$f1" ]]
then
echo "$f1: No such file." >&2
exit 1
fi
if [ ! -f "$f2" ]
if [[ "$f2" != '/dev/null' ]] && [[ ! -f "$f2" ]]
then
echo "$f2: No such file." >&2
usage
exit 1
fi
if [ -z "$name1" ]
if [[ -z "$name1" ]]
then
name1="$f1"
fi
if [ -z "$name2" ]
if [[ -z "$name2" ]]
then
name1="$f2"
fi
@ -93,14 +93,14 @@ fi
exif()
{
if [ "$1" = /dev/null ]
if [[ "$1" = /dev/null ]]
then
echo /dev/null
return
fi
local b=$(basename "$1")
local d=$(mktemp -t "$b")
local b="$(basename "$1")"
local d="$(mktemp -t "$b.XXXXXX")"
exiftool "$1" | grep -v 'File Name' | \
grep -v 'Directory' | \
@ -121,10 +121,10 @@ diff_clean_names()
}
if which -s exiftool
if which exiftool > /dev/null
then
d1=$(exif "$f1")
d2=$(exif "$f2")
d1="$(exif "$f1")"
d2="$(exif "$f2")"
diff_clean_names "$d1" "$d2"
else
diff_clean_names "$f1" "$f2"
@ -136,8 +136,8 @@ then
fi
if \
! which -s compare || \
! which -s montage
! which compare > /dev/null || \
! which montage > /dev/null
then
echo 'ImageMagick is not installed.' >&2
exit 1
@ -148,8 +148,8 @@ then
exit 0
fi
bn=$(basename "$f1")
destfile=$(mktemp -t "$bn").png
bn="$(basename "$f1")"
destfile="$(mktemp -t "$bn.XXXXXX").png"
if [ -z "$fuzz" ] && ( [ "$ext" = "jpeg" ] || [ "$ext" = "jpg" ] )
then
@ -170,4 +170,9 @@ fi
compare $color_flag $fuzz_flag "$f1" "$f2" png:- | \
montage -geometry +4+4 "$f1" - "$f2" png:- >"$destfile" 2>/dev/null || true
open "$destfile"
if which xdg-open > /dev/null
then
xdg-open "$destfile"
else
open "$destfile"
fi

View File

@ -53,12 +53,12 @@ readlink_f()
fi
}
thisdir=$(dirname $(readlink_f "$0"))
thisdir="$(dirname $(readlink_f "$0"))"
e_flag=''
if [ -z "${GIT_DIFF_IMAGE_ENABLED-}" ] || \
! which -s compare || \
! which -s montage
! which compare > /dev/null || \
! which montage > /dev/null
then
e_flag='-e'
fi