#!/bin/sh
#
# Usage: creating dirs
# IDs do not have to be hex strings:
# "book-scanning:54f757919a5ede59" or "arduino-tools:3b6b4f47bf803663"
#
#   #!/bin/sh
#   N=${1:-8} # number of bytes
#   xxd -g "${N}" -c "${N}" -p -l "${N}" </dev/urandom

ID=${1:?Must specific ID}
IDSHA=$(echo "${ID}" | shasum | cut -d ' ' -f 1)
mdfind "${ID}" 2>/dev/null | grep /ID | while read -r F; do
  FSHA=$(shasum "${F}" | cut -d ' ' -f 1)
  if [ "${IDSHA}" = "${FSHA}" ]; then
    dirname "${F}"
    exit 0
  fi
done
exit 1
