#!/bin/sh -e

outfile="$1"
selection="$2"

if [ -z "${outfile}" ]; then
  outfile="$(date +%Y-%m-%d--%H-%M-%S)-$$.png"
fi

if [ -n "${WAYLAND_DISPLAY}" ]; then
  if [ -n "${selection}" ]; then
    grim -g "${selection}" "${outfile}"
  else
    grim "${outfile}"
  fi
else
  if [ -n "${selection}" ]; then
    scrot -a "${selection}" "${outfile}"
  else
    scrot "${outfile}"
  fi
fi
