-
Notifications
You must be signed in to change notification settings - Fork 30
/
install.sh
executable file
·98 lines (80 loc) · 2.31 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
set -euo pipefail
cols=80
if [ -n "${TERM-}" ] && [ "$TERM" != "dumb" ]
then
cols=$(tput cols)
fi
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 bmp
addattr gif
addattr heic
addattr jpeg
addattr jpg
addattr png
addattr svg
echo '+ git config --global alias.diff-image '"'"'!f() { cd -- "${GIT_PREFIX:-.}"; GIT_DIFF_IMAGE_ENABLED=1 git diff "$@"; }; f'"'"
git config --global alias.diff-image '!f() { cd -- "${GIT_PREFIX:-.}"; 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"
bin_diff_image_tilde="~/bin/diff-image"
bin_diff_image="${bin_diff_image_tilde/#\~/$HOME}"
if [ -e "$bin_diff_image" ]
then
echo "# Leaving $bin_diff_image alone."
else
if [ ! -d "$HOME/bin" ]
then
echo "+ mkdir -p ~/bin"
mkdir -p "$HOME/bin"
fi
echo "+ ln -s $thisdir_tilde/diff-image ~/bin/"
ln -s "$thisdir/diff-image" "$HOME/bin/"
fi