#!/bin/sh -e

die() {
  printf "ERROR: %s.\n" "$1" >&2
  exit 1
}

target=${1:-${PWD}}
hash_command="sha256sum"

if [ -d "${target}" ]; then
  fd --full-path "${target}" --base-directory "${target}" -t f -x "${hash_command}" \
    | sort | ${hash_command} | awk '{ print $1 }'
elif [ -f "${target}" ]; then
  ${hash_command} "${target}" | awk '{ print $1 }'
fi
