#!/usr/bin/env bash

# A simple script to mass rename all the wallpapers in a specified directory

if [ "$#" -eq 0 ]; then
    echo "Usage: $0 <wallpaper_directory>"
    exit 1
fi

WALL_DIR="$1"

# Check if the directory exists
if [ ! -d "$WALL_DIR" ]; then
    echo "Directory does not exist. Exiting..."
    exit 1
fi

cd "$WALL_DIR"

# Prompt the user for the starting counter value
read -p "Enter the starting counter value: " counter

# Validate if the input is a positive integer
if ! [[ "$counter" =~ ^[1-9][0-9]*$ ]]; then
    echo "Invalid input. Please enter a positive integer."
    exit 1
fi

for file in *.png *.jpeg *.jpg; do
    if [ -e "$file" ]; then
        extension="${file##*.}"

        new_filename="${counter}.${extension}"
        mv "$file" "$new_filename"
        counter=$((counter+1))
    fi
done

echo "Renaming complete."
