Skip to content

Instantly share code, notes, and snippets.

@pvdb
Last active March 14, 2023 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvdb/557c701908777b30f2b3ebfd95b25002 to your computer and use it in GitHub Desktop.
Save pvdb/557c701908777b30f2b3ebfd95b25002 to your computer and use it in GitHub Desktop.
#!/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