diff options
| author | xengineering <me@xengineering.eu> | 2025-12-23 11:26:34 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2025-12-23 11:28:21 +0100 |
| commit | d0bad95968b0ad1bda7ef694fdf5b8e7f396faa6 (patch) | |
| tree | 4b34badf8ff41d9b88765ad662eec5e9a75a371d /posix-shell/utils.sh | |
| parent | 9e41ce623a5c4b6d426fd75fed338d02736e03d3 (diff) | |
| download | dotfiles-d0bad95968b0ad1bda7ef694fdf5b8e7f396faa6.tar dotfiles-d0bad95968b0ad1bda7ef694fdf5b8e7f396faa6.tar.zst dotfiles-d0bad95968b0ad1bda7ef694fdf5b8e7f396faa6.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.sh | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/posix-shell/utils.sh b/posix-shell/utils.sh index 4354a37..b21c09b 100644 --- a/posix-shell/utils.sh +++ b/posix-shell/utils.sh @@ -258,3 +258,21 @@ lar() { popd rm -rf "$temporary_directory" } + +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" +} |
