2022-10-24 20:22:45 +00:00
|
|
|
#!/bin/bash -e
|
2021-07-29 14:02:20 +00:00
|
|
|
# interactive diff with pagination and nice coloring
|
2022-10-24 20:22:45 +00:00
|
|
|
declare -a files
|
|
|
|
while test $# -gt 0
|
|
|
|
do test "$1" == "--" && shift &&
|
|
|
|
command="$@" && break
|
|
|
|
files+=("$1")
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
{
|
|
|
|
if ! test "$command"; then
|
|
|
|
mime="$(file --brief --mime "${files[@]}")"
|
|
|
|
case "$mime" in
|
|
|
|
(*audio*) command="ffprobe -loglevel warning -print_format default=noprint_wrappers=1 -show_format -pretty";;
|
|
|
|
(image/*) command="exiftool";;
|
|
|
|
(*sqlite*) sqldiff --summary "${files[@]}" | grep -v '0 changes, 0 inserts, 0 deletes';; # TODO syntax highlighting for INSERT/UPDATE/DELETE
|
|
|
|
(text/*)
|
2023-11-04 18:08:39 +00:00
|
|
|
# Use wiked-diff only for text <100KB
|
2024-09-15 14:42:56 +00:00
|
|
|
test 100000 -gt "$(stat --format=%s "${files[@]}" | paste -s -d'+' | bc)" &&
|
|
|
|
wiked-diff "${files[@]}" ||
|
|
|
|
diff --color=always --unified=1 --report-identical-files "${files[@]}"
|
|
|
|
;;
|
2022-10-24 20:22:45 +00:00
|
|
|
(*) diff-color --report-identical-files "${files[@]}";;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
if test "$command"; then
|
|
|
|
echo "Generated through $command"
|
2022-09-30 18:01:37 +00:00
|
|
|
$(test $(tput cols) -gt 120 && echo "diff --color=always --side-by-side" || echo "diff-color") \
|
2024-04-08 11:02:09 +00:00
|
|
|
--ignore-case --report-identical-files --label="${files[0]}" --label="${files[1]}" <($command "${files[0]}") <($command "${files[1]}")
|
2022-10-24 20:22:45 +00:00
|
|
|
fi
|
|
|
|
} | less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen
|