Created
December 6, 2021 08:32
-
-
Save fumiyas/bae42097671f06fac6a790db985801ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## | |
## ~/bin/diff-highlight | |
## | |
set -u | |
if [ -n "${BASH+set}" ]; then | |
shopt -s lastpipe 2>/dev/null ## Bash 4.2+ for `exec ... |exec ...` | |
fi | |
if type perl >/dev/null 2>&1; then | |
if [ -n "${GIT_EXEC_PATH+set}" ]; then | |
git_prefix="${GIT_EXEC_PATH%/*}/../share" | |
else | |
git_prefix="/usr/share" | |
fi | |
git_diff_highlight_dir=$(echo "${git_prefix}"/doc/*git*/contrib/diff-highlight) | |
if [ -d "$git_diff_highlight_dir" ]; then | |
diff_highlight() { | |
exec perl \ | |
-I "$git_diff_highlight_dir" \ | |
-e ' | |
use DiffHighlight; | |
$SIG{PIPE} = "DEFAULT"; | |
DiffHighlight::highlight_stdin(); | |
exit 0; | |
' \ | |
; | |
} | |
fi | |
fi | |
if [ -n "${GIT_EXEC_PATH+set}" ] && type diff_highlight >/dev/null 2>&1; then | |
diff_highlight | |
exit $? | |
fi | |
for n in diff-highlight colordiff; do | |
for p in /usr/local/bin /usr/bin; do | |
c="$p/$n" | |
if [ -x "$c" ]; then | |
if type nkf >/dev/null 2>&1; then | |
exec nkf -x -m0 |exec "$c" "$@" | |
else | |
exec "$c" "$@" | |
fi | |
exit $? | |
fi | |
done | |
done | |
if type diff_highlight >/dev/null 2>&1; then | |
diff_highlight | |
exit $? | |
fi | |
exec cat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment