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/.config/bash/module/checksum.sh

38 lines
820 B
Bash
Raw Normal View History

2023-08-08 16:24:15 +03:00
# create or check checksums for all files in current directory.
2023-10-30 03:49:10 +03:00
# usage: checksum <ACTION>
# actions: "new", "check".
2023-08-08 16:24:15 +03:00
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"
2023-08-08 16:24:15 +03:00
# 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)."
2023-11-20 18:39:04 +03:00
return 2
2023-08-08 16:24:15 +03:00
}
2023-10-23 00:36:27 +03:00
# autocomplete.
_checksum()
{
2023-10-23 03:31:00 +03:00
_autocomplete_first "{new,check}"
2023-10-23 00:36:27 +03:00
}
complete -F _checksum checksum