#!/usr/bin/env sh

# Screenshot menu options with icons
OPTIONS="󰍹  All Screens\n󰹑  Active Screen\n\ueb7f  Select Window\n󰩬  Select Area"

# Get selection from argument or rofi menu
if [ -n "$1" ]; then
    CHOICE="$1"
else
    CHOICE=$(echo -e "$OPTIONS" | rofi -dmenu -p "Screenshot:" -theme-str 'window {width: 250px; height: 250px;}')
    # Strip icon from selection (remove everything before and including the first space)
    CHOICE=$(echo "$CHOICE" | sed 's/^[^ ]* *//')
fi

# Execute based on selection
case "$CHOICE" in
"All Screens")
    grimshot --notify savecopy screen
    ;;
"Active Screen")
    grimshot --notify savecopy output
    ;;
"Select Window")
    grimshot --notify savecopy window
    ;;
"Select Area")
    grim -g "$(slurp)" - | swappy -f -
    ;;
*)
    # User cancelled or invalid selection
    exit 0
    ;;
esac
