Skip to content

Instantly share code, notes, and snippets.

@abathur
Last active January 10, 2022 22:21
Show Gist options
  • Save abathur/6189c15922c918171e18728ef3563594 to your computer and use it in GitHub Desktop.
Save abathur/6189c15922c918171e18728ef3563594 to your computer and use it in GitHub Desktop.
Confirming how portable this diff invocation is/isn't on any OS you can/want to install Nix on that isn't already in reports! This tries each diff on PATH, but I'm interested in default and common user-installed diffs (leave out any uncommon build you have). See 1st comment for a screenshot of expected output.
#!/usr/bin/env bash
readonly ESC='\033[0m'
readonly GREEN='\033[32m'
readonly RED='\033[31m'
printf -v _UNCHANGED_GRP_FMT "%b" $'\033[2m%='"$ESC" # "dim"
# bold+invert+red and bold+invert+green just for the +/- below
# red/green foreground for rest of the line
printf -v _OLD_LINE_FMT "%b" $'\033[1;7;31m-'"$ESC ${RED}%L${ESC}"
printf -v _NEW_LINE_FMT "%b" $'\033[1;7;32m+'"$ESC ${GREEN}%L${ESC}"
for diff in $(type -ap diff); do
$diff --unchanged-group-format="$_UNCHANGED_GRP_FMT" --old-line-format="$_OLD_LINE_FMT" --new-line-format="$_NEW_LINE_FMT" --unchanged-line-format=" %L" <(echo one && echo two && echo three) <(echo one && echo tow && echo three)
echo "^^^ status: $? for $($diff --version | head -n 1) ($diff)"
done
working
macOS 10.14, 10.15, 10.16
stock: (GNU diffutils) 2.8.1 (/usr/bin/diff)
fink, homebrew, macports, pkgsrc: I haven't found an obvious bin/diff except the one in diffutils, which should be fine
centOS 6
not working
* nixpkgs plan9port/bin/diff (completely incompatible: diff [ -acefmnbwr ] file1 ... file2)
@abathur
Copy link
Author

abathur commented Nov 28, 2020

Expected output is something like:
Screen Shot 2020-11-28 at 11 42 38 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment