dimo414 / bash-cache

Transparent caching layer for bash functions; particularly useful for functions invoked as part of your prompt.
GNU General Public License v3.0
73 stars 4 forks source link

Improve argument hashing behavior #19

Closed dimo414 closed 4 years ago

dimo414 commented 4 years ago

The current implementation is somewhat collision-prone; it uses $* which collapses separate arguments into a space-delimited string, meaning calling a function with a single argument 'a b c' will hash to the same identifier as three separate arguments 'a' 'b' 'c'.

The existing hashing behavior could be made more plug-able as well. Users should be able to specify a particular function/command to use as the hash function (e.g. to tune performance). Something like:

if [[ -n "$BC_HASH_COMMAND" ]]; then
  _bc_hash_command="$BC_HASH_COMMAND"
elif command -v sha1sum &> /dev/null; then
  _bc_hash_command=sha1sum
elif ...
fi
if [[ -z "_bc_hash_command" ]]; then
  error!
fi