summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krautmacher <jan.krautmacher@indurad.com>2025-09-25 07:19:31 +0200
committerxengineering <me@xengineering.eu>2025-09-25 07:35:06 +0200
commit6df549d1234f6a50d79ce56a367addc8ec263a16 (patch)
tree0ff2e8b64a2dd996c66168dd7c94eea873b3290f
parent754fe43f482b7fe41a52f84074e8ee5b1083d21a (diff)
downloaddotfiles-6df549d1234f6a50d79ce56a367addc8ec263a16.tar
dotfiles-6df549d1234f6a50d79ce56a367addc8ec263a16.tar.zst
dotfiles-6df549d1234f6a50d79ce56a367addc8ec263a16.zip
posix-shell: utils: Add hexdiff()
This tool outputs the diff of two hexdumps based on the two files provided as arguments.
-rw-r--r--posix-shell/utils.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/posix-shell/utils.sh b/posix-shell/utils.sh
index b1ffc21..f19602d 100644
--- a/posix-shell/utils.sh
+++ b/posix-shell/utils.sh
@@ -225,3 +225,21 @@ lar() {
popd
rm -rf "$temp"
}
+
+hexdiff() {
+ if test "$#" -ne 2
+ then
+ echo "Usage: hexdiff <file1> <file2>"
+ return 1
+ fi
+
+ dump1="$(mktemp)"
+ dump2="$(mktemp)"
+
+ hexdump -C "$1" > "$dump1"
+ hexdump -C "$2" > "$dump2"
+
+ diff --unified=4 --color=always "$dump1" "$dump2"
+
+ rm -f "$dump1" "$dump2"
+}