Files
git-diff-image/git_diff_image
Ewan Mellor 92caf772dc Break the script into two, so that we can use it as a normal CLI command,
as well as the existing "git diff" functionality.
2018-04-20 10:24:07 -07:00

68 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
name="$1"
f1="$2"
f2="$5"
name1="a/$name"
name2="b/$name"
if [ "$f1" = /dev/null ]
then
name1=/dev/null
fi
if [ "$f2" = /dev/null ]
then
name2=/dev/null
fi
if diff "$f1" "$f2" >/dev/null
then
exit 0
fi
readlink_f()
{
if [ $(uname) = 'Darwin' ]
then
local f=$(readlink "$1")
if [ -z "$f" ]
then
f="$1"
fi
local d=$(dirname "$f")
local b=$(basename "$f")
if [ -d "$d" ]
then
(cd "$d" && echo "$(pwd -P)/$b")
elif [[ "$d" = /* ]]
then
echo "$f"
elif [[ "$d" = ./* ]]
then
echo "$(pwd -P)/${f/.\//}"
else
echo "$(pwd -P)/$f"
fi
else
readlink -f "$1"
fi
}
thisdir=$(dirname $(readlink_f "$0"))
e_flag=''
if [ -z "${GIT_DIFF_IMAGE_ENABLED-}" ] || \
! which -s compare || \
! which -s montage
then
e_flag='-e'
fi
exec "$thisdir/diff-image" $e_flag -n "$name1" -N "$name2" "$f1" "$f2"