#!/usr/bin/env bash
set -eou pipefail

read -rep $'Do you want to rename all files in this dir to their hash? [Y/n] \n> ' -n 1 REPLY
REPLY=${REPLY:-Y}
if [[ $REPLY =~ ^[Yy]$ ]]
then
    for file in *; do
        if [[ -f "./$file" ]]; then
            sum=$(echo -n "$file" | md5sum)
            echo "$file --> ${sum%% *}.${file##*.}"
            mv "$file" "${sum%% *}.${file##*.}"
        fi
    done
fi
