#!/bin/bash

# Define the path where .desktop files will be created
desktop_path="$HOME/.local/share/applications"

# Output of the alias list-firefox-profiles
profiles=$(awk -F= "/Name=/{print \$2}" ~/.mozilla/firefox/profiles.ini | sort)

# Loop through each profile and create the corresponding .desktop file
IFS=$'\n' # Set Internal Field Separator to newline to handle profiles with spaces
for profile in $profiles; do
    desktop_file="$desktop_path/$profile.desktop"

    echo "[Desktop Entry]" > "$desktop_file"
    echo "Encoding=UTF-8" >> "$desktop_file"
    echo "Version=1.0" >> "$desktop_file"
    echo "Type=Application" >> "$desktop_file"
    echo "Terminal=false" >> "$desktop_file"
    echo "Exec=/usr/bin/firefox --no-remote -P $profile --class $profile" >> "$desktop_file"
    echo "Name=$profile" >> "$desktop_file"

    echo "Created $desktop_file"
done
