#!/bin/sh

set -eu

mode=${1:-full}
target_dir="$HOME/Pictures/Screenshots"
target_file="$target_dir/$(date +%Y-%m-%d-%H%M%S).png"

mkdir -p "$target_dir"

case "$mode" in
  full)
    grim "$target_file"
    ;;
  region)
    grim -g "$(slurp)" "$target_file"
    ;;
  output)
    grim -g "$(slurp -o)" "$target_file"
    ;;
  *)
    printf 'Usage: %s [full|region|output]\n' "$0" >&2
    exit 1
    ;;
esac

if command -v wl-copy >/dev/null 2>&1; then
  wl-copy < "$target_file"
fi

if command -v notify-send >/dev/null 2>&1; then
  notify-send "Screenshot saved" "$target_file"
fi
