#!/usr/bin/env zsh # Diffs two PDF files using pdftotext and wdiff. emulate -LR zsh if [[ $# -lt 2 ]] then echo "Usage: pdfwdiff [diff_options] file1.pdf file2.pdf" >&2 return 1 fi # The user may prefer his own cwdiff function (or external command) rather # than the following one, provided in case cwdiff is not available. # Changing '30;41' to 97;41' and '30;42' to '97;48;5;28' makes text more # readable (tested on various devices), but needs a 256-color terminal, # which are common nowadays. cwdiff_fallback() { wdiff -n -w $'\033[30;41m' -x $'\033[0m' \ -y $'\033[30;42m' -z $'\033[0m' -d "$@" return $(( $? == 1 ? 0 : $? )) } eval "autoload -R cwdiff 2> /dev/null" if [[ $? == 0 ]] || whence -p cwdiff > /dev/null; then cmd=cwdiff else cmd=cwdiff_fallback fi diff -u "$@[1,-3]" <(pdftotext "$@[-2]" -) \ <(pdftotext "$@[-1]" -) | $cmd # $Id: pdfwdiff 150114 2022-07-13 13:29:25Z vinc17/zira $