| ... | ... |
@@ -1,15 +1,32 @@ |
| 1 | 1 |
#!/bin/sh |
| 2 | 2 |
set -euC |
| 3 | 3 |
|
| 4 |
-# Where `diff-highlight` is located and whether it's executable varies between |
|
| 5 |
-# distros, so try a few common places and run the shebang manually. |
|
| 4 |
+# Distros (or upstream git, I'm not sure) make it very annoying to actually use |
|
| 5 |
+# the shipped `diff-highlight`. The following things vary depending on distro |
|
| 6 |
+# and version: |
|
| 7 |
+# - Where it is located |
|
| 8 |
+# - If it has a file extension |
|
| 9 |
+# - Whether it's executable |
|
| 10 |
+# - Whether has a shebang |
|
| 11 |
+# Therefore, we are left with this shim which does its best to actually run the |
|
| 12 |
+# thing. |
|
| 6 | 13 |
|
| 7 | 14 |
for file in \ |
| 8 |
- '/usr/share/doc/git/contrib/diff-highlight/diff-highlight' \ |
|
| 9 |
- '/usr/share/git-core/contrib/diff-highlight' \ |
|
| 10 |
- '/usr/share/git/diff-highlight/diff-highlight' |
|
| 15 |
+ '/usr/share/doc/git/contrib/diff-highlight/diff-highlight'* \ |
|
| 16 |
+ '/usr/share/git-core/contrib/diff-highlight'* \ |
|
| 17 |
+ '/usr/share/git/diff-highlight/diff-highlight'* |
|
| 11 | 18 |
do |
| 12 |
- [ -e "$file" ] && break |
|
| 19 |
+ # Does it exist? |
|
| 20 |
+ [ -r "$file" ] || continue |
|
| 21 |
+ # Is it executable? |
|
| 22 |
+ [ -x "$file" ] && exec "$file" || true |
|
| 23 |
+ # Does it have a shebang? |
|
| 24 |
+ interp="$(sed -n '1s/^#!//p' "$file")" |
|
| 25 |
+ [ "$interp" ] && exec $interp "$file" "$@" || true |
|
| 26 |
+ # Does it have a file extension which matches a command? |
|
| 27 |
+ ext="${file##*.}"
|
|
| 28 |
+ [ "$(command -v "$ext")" ] && exec "$ext" "$file" "$@" || true |
|
| 13 | 29 |
done |
| 14 |
-prog="$(sed -n '1s/^#!//p' "$file")" |
|
| 15 |
-exec $prog "$file" "$@" |
|
| 30 |
+ |
|
| 31 |
+# Fallback. |
|
| 32 |
+exec cat |
| 1 | 1 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,15 @@ |
| 1 |
+#!/bin/sh |
|
| 2 |
+set -euC |
|
| 3 |
+ |
|
| 4 |
+# Where `diff-highlight` is located and whether it's executable varies between |
|
| 5 |
+# distros, so try a few common places and run the shebang manually. |
|
| 6 |
+ |
|
| 7 |
+for file in \ |
|
| 8 |
+ '/usr/share/doc/git/contrib/diff-highlight/diff-highlight' \ |
|
| 9 |
+ '/usr/share/git-core/contrib/diff-highlight' \ |
|
| 10 |
+ '/usr/share/git/diff-highlight/diff-highlight' |
|
| 11 |
+do |
|
| 12 |
+ [ -e "$file" ] && break |
|
| 13 |
+done |
|
| 14 |
+prog="$(sed -n '1s/^#!//p' "$file")" |
|
| 15 |
+exec $prog "$file" "$@" |