#!/bin/bash
# take a screenshot
# usage: shot [region|full] [path|data]

FNAME=$(date +%F-%H-%M-%S)
TPATH=/tmp/$FNAME.png
FPATH=~/docs/shots/$FNAME.webp

# if nothing specified, ask
if [ -z $1 ]; then
    choice=$(echo -e "full\nregion" | bemenu -p "shot")
else
    choice=$1
fi

case $choice in
    "region")
        grim -g "$(slurp)" $TPATH;;

    "full")
        grim $TPATH;;

    *) exit 1;;
esac

if [ -f $TPATH ]; then
    magick $TPATH $FPATH

    notify-send -t 5000 "screenshot saved to $FPATH"

    if [ -z $2 ]; then
        choice=$(echo -e "path\ndata" | bemenu -i -p "copy")
    else
        choice=$2
    fi
    case $choice in
        "path") echo -n "$FPATH " | wl-copy;;
        "data") wl-copy < "$TPATH";;
        *) ;;
    esac
    echo $FPATH
fi
