This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.linux/bash/module/checksum.sh

38 lines
819 B
Bash

# create or check checksums for all files in current directory.
# usage: checksum <ACTION>
# actions: "new", "check".
checksum()
{
local action="$1" # what to do with checksum.
local file="checksum.sha1" # file name to store checksums.
if [[ "$action" =~ ^(n|new)$ ]]; then
# create checksums for all files.
find -type f | parallel sha1sum {} > "$file"
# remove checksum file from resulting hashes.
sed -i "/$file/d" "$file"
return 0
fi
if [[ "$action" =~ ^(c|check)$ ]]; then
# check checsums for all files.
sha1sum --quiet -c ./checksum.sha1
return 0
fi
# error on wrong action.
echo "supported actions: new (n), check (c)."
return 1
}
# autocomplete.
_checksum()
{
_autocomplete_first "{new,check}"
}
complete -F _checksum checksum