summaryrefslogtreecommitdiff
path: root/posix-shell/utils.sh
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2025-09-25 07:19:31 +0200
committerxengineering <me@xengineering.eu>2025-09-25 07:35:06 +0200
commit8c1098fa67718cb0d6d2a5cf168928e021fe34be (patch)
tree0ff2e8b64a2dd996c66168dd7c94eea873b3290f /posix-shell/utils.sh
parent19624abeaa0e5ec178f58e07e5a9f71802487755 (diff)
downloaddotfiles-8c1098fa67718cb0d6d2a5cf168928e021fe34be.tar
dotfiles-8c1098fa67718cb0d6d2a5cf168928e021fe34be.tar.zst
dotfiles-8c1098fa67718cb0d6d2a5cf168928e021fe34be.zip
posix-shell: utils: Add hexdiff()
This tool outputs the diff of two hexdumps based on the two files provided as arguments.
Diffstat (limited to 'posix-shell/utils.sh')
-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"
+}