#!/usr/bin/env bash
# Find the most recent screenshot in ~/Pictures/Screenshots

set -euo pipefail

SCREENSHOT_DIR="${HOME}/Pictures/Screenshots"

# Check if directory exists
if [[ ! -d "$SCREENSHOT_DIR" ]]; then
    echo "Error: Screenshots directory not found at $SCREENSHOT_DIR" >&2
    exit 1
fi

# Find most recent screenshot (sorted by modification time, newest first)
latest=$(ls -t "$SCREENSHOT_DIR"/*.{png,jpg,jpeg} 2>/dev/null | head -1 || true)

if [[ -z "$latest" ]]; then
    echo "Error: No screenshots found in $SCREENSHOT_DIR" >&2
    exit 1
fi

echo "$latest"
