#! /nix/store/kxkdrxvc3da2dpsgikn8s2ml97h88m46-bash-interactive-5.2-p15/bin/bash
#! nix-shell -i bash -p bash fd ripgrep

base_directory='/srv/disk2/scrapping/JawZ'
gdl_directory=$base_directory/gallery-dl
filtered_directory=$base_directory/organized

move_files() {
    orig_file=$(realpath "$1")

    dest_file=${orig_file//$gdl_directory/$filtered_directory}
    dest_dir=$(realpath "$(dirname "$dest_file")")

    mkdir -vp "$dest_dir"
    command mv -in "$orig_file" "$dest_dir"
}

if [ -z "$1" ]; then
    echo "Please drag a few directories or files!"
else
    for arg in "$@"; do
        if [ -d "$arg" ]; then
            while IFS= read -r file; do
                move_files "$file"
            done < <(fd . "$arg" -tf)
        elif [ -f "$arg" ]; then
            move_files "$arg"
        else
            echo "It's neither a file or a directory"
            echo "Please check your input"
        fi
    done
fi
