#!/bin/sh
printusage() { echo -n "Usage: $0 [-cx]\nOptions:\n-c\tInteractively crop screenshot\n-x\tCopy screenshot to clipboard with xclip rather than saving it\n" && exit; }

# scrot and xclip opts
fmt=$(date '+%m-%d-%4Y_%I:%M:%S_%p.png')
tmppath=/tmp/$fmt
savpath=~/pics/screenshots/$fmt
normopt=''
cropopt='--select --freeze'
normexp='echo $f'
xclipexp='xclip -selection clipboard -target image/png -i $f && echo $f'

# notify-send opts
notifyopts="--expire-time 4000 --urgency low"
normsumm="Screenshot Saved!"
xclipsumm="Screenshot Copied!"
normbody="Screenshot saved as \"$fmt\""
xclipbody="Screenshot copied to clipboard"

# Default opts
opt=$normopt
path=$savpath
exp=$normexp

summ=$normsumm
body=$normbody

while getopts "cxh" arg; do
	case "$arg" in
		c) opt=$cropopt ;;
		x) path=$tmppath; exp=$xclipexp; summ=$xclipsumm; body=$xclipbody ;;
		h) printusage ;;
		*) printusage ;;
	esac
done

scrot $opt $path --exec "$exp" \
&& notify-send $notifyopts -i $path "$summ" "$body" \
|| notify-send $notifyopts "Screenshot Failed!"