Files
git-diff-image/install.sh
Ewan Mellor 35abd26ba5 Added.
2015-05-02 20:04:24 -07:00

78 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
set -eu
set -o pipefail
cols=$(tput cols)
readlink_f() {
if [ $(uname) = 'Darwin' ]
then
local d=$(echo "${1%/*}")
local f=$(basename "$1")
(cd "$d" && echo "$(pwd -P)/$f")
else
readlink -f "$1"
fi
}
addattr() {
ext="$1"
if ! grep -qE "^\*.$ext diff=image\$" "$attributesfile"
then
if grep -qE "^\*.$ext" "$attributesfile"
then
fold -s -w$cols >&2 <<EOS
$attributesfile already has *.$ext configured, but not the way that this script requires.
If you want to use git-image-diff with $ext files, you must add a diff=image attribute yourself.
EOS
else
echo "+ echo '*.$ext diff=image' >>'$attributesfile'"
echo "*.$ext diff=image" >>"$attributesfile"
fi
fi
}
thisdir=$(dirname $(readlink_f "$0"))
thisdir_tilde="${thisdir/#$HOME/~}"
attributesfile_tilde=$(git config --global core.attributesfile || true)
attributesfile="${attributesfile_tilde/#\~/$HOME}"
if [ -z "$attributesfile" ]
then
attributesfile="$HOME/.gitattributes"
attributesfile_tilde="~/.gitattributes"
echo "+ git config --global core.attributesfile '$attributesfile_tilde'"
git config --global core.attributesfile "$attributesfile_tilde"
fi
if [ ! -f "$attributesfile" ]
then
if [ ! -e "$attributesfile" ]
then
echo "+ touch '$attributesfile'"
touch "$attributesfile"
else
echo "$attributesfile is not a regular file! I give up." >&2
exit 1
fi
fi
addattr gif
addattr jpeg
addattr jpg
addattr png
echo '+ git config --global alias.diff-image '"'"'!f() { GIT_DIFF_IMAGE_ENABLED=1 git diff "$@"; }; f'"'"
git config --global alias.diff-image '!f() { GIT_DIFF_IMAGE_ENABLED=1 git diff "$@"; }; f'
echo "+ git config --global diff.image.command '$thisdir_tilde/git_diff_image'"
git config --global diff.image.command "$thisdir_tilde/git_diff_image"