Skip to content

Instantly share code, notes, and snippets.

@rindeal
Last active March 17, 2024 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rindeal/21218d51c2c52b157e2089e4c3ad6b71 to your computer and use it in GitHub Desktop.
Save rindeal/21218d51c2c52b157e2089e4c3ad6b71 to your computer and use it in GitHub Desktop.
Generate multiple hashes for a file and print them as a markdown table
#!/bin/sh
# requires `pee` command from `moreutils` suite
SUMS=(
md5sum
sha1sum
sha256sum
)
FILE="${1}"
printf '<details>\n'
printf '<summary>Checksums for <code>%s</code>:</summary>\n\n' "${FILE}"
pee "${SUMS[@]}" < "${FILE}" | \
awk '
BEGIN {
'"$(
for i in $(seq 1 ${#SUMS[@]})
do
printf 'a[%d]=\"%s\"\n' $i "${SUMS[$((i - 1))]}"
done
)"'
print "Name | Value"
print "-------------- | -----------------------"
}
a[NR] {
printf "%-14s | %s\n", "**"a[NR]"**", $1
}
'
printf '\n</details>\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment