Last active
March 14, 2023 12:28
-
-
Save pvdb/557c701908777b30f2b3ebfd95b25002 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
#!/usr/bin/env zsh | |
# | |
# INSTALLATION | |
# | |
# ln -s ${PWD}/xdiff $(brew --prefix)/bin/ | |
# sudo ln -s ${PWD}/xdiff /usr/local/bin/ | |
# | |
REPORT="$1" ; shift ; | |
# check command-line options | |
[ -z "$*" ] && { | |
>&2 echo 'Usage: xdiff "<report>" <command(s)>' ; | |
exit 1 ; | |
} | |
# check report command(s) | |
[ -z "${REPORT}" ] && { >&2 echo 'Missing report command(s)' ; exit 1 ; } | |
# capture the report output before & after | |
# running the actual commands, and diff it | |
BEFORE_EXEC="$(mktemp -t before)" ; | |
AFTER_EXEC="$(mktemp -t after)" ; | |
trap 'rm -f "${BEFORE_EXEC}" "${AFTER_EXEC}"' EXIT ; | |
> ${BEFORE_EXEC} ${=REPORT} ; | |
"$@" ; # run the actual command(s) | |
> ${AFTER_EXEC} ${=REPORT} ; | |
( | |
echo "--- \"${REPORT}\" (before) ;" ; | |
echo "+++ \"${REPORT}\" (after) ;" ; | |
) | colordiff > /dev/tty ; | |
( | |
colordiff --unified=20 --report-identical-files ${BEFORE_EXEC} ${AFTER_EXEC} ; | |
) | grep -E -v "(---|\+\+\+) ${TMPDIR}" > /dev/tty ; | |
# That's all Folks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment