Skip to content

Commit

Permalink
chore: Refactor checksum utility alias section to avoid repetition.
Browse files Browse the repository at this point in the history
Shall not interfere with firasuke#43.
  • Loading branch information
takusuman committed Dec 27, 2024
1 parent 5332628 commit 451e014
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions mussel
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,24 @@ osslchecksum() {
}

# ----- Checksum utility alias ----- #
checksum() {
# First of all, alias the command to be used with a generic
# boilerplate function.
# Since the shell, in any POSIX-compliant implementation, maintains
# function declarations in a stack different from variables, we can
# use 'checksum_command' as the identifier for both the variable
# that contains the type of hash check mechanism and the boilerplate
# function.
case "$checksum_command" in
# check the hash with b3sum
[ "$checksum_command" = "b3sum" ] && {
printf "$1 $2" | b3sum -c
return $?
}

'b3sum') checksum_command() { b3sum -c; } ;;
# check the hash with sha256sum
[ "$checksum_command" = "sha256sum" ] && {
printf "$1 $2" | sha256sum -c
return $?
}

'sha256sum') checksum_command() { sha256sum -c; } ;;
# check the hash with openssl
[ "$checksum_command" = "openssl" ] && {
printf "$1 $2" | osslchecksum
return $?
}
'openssl') checksum_command() { osslchecksum; } ;;
esac
checksum() {
printf '%s %s' $1 "$2" | checksum_command
return $?
}

# Stone-portable way to get the processor number of cores on
Expand Down

0 comments on commit 451e014

Please sign in to comment.