#!/usr/bin/env bash
set -e

# Dependencies:
# - slurp
# - grim

ACTION=$1

DATESTAMP=$(date +"%Y%m%d%H%M%S")
OUT_DIR="${HOME}/screenshots"
OUT_FILE="capture-${ACTION}-${DATESTAMP}.png"

case $ACTION in
    region)
        [[ ! -d "${OUT_DIR}" ]] && mkdir $OUT_DIR
        slurp | grim -t png -g - "${OUT_DIR}/${OUT_FILE}"
        ;;
    screen)
        [[ ! -d "${OUT_DIR}" ]] && mkdir $OUT_DIR
        grim -t png "${OUT_DIR}/${OUT_FILE}"
        ;;
    *)
        echo "Unknown action"
        exit 1
        ;;
esac
