#!/usr/bin/env bash
# scr: screenshot tool

scr_path=~/pics/scrots
output="$(tr -dc 'a-zA-Z0-9' < /dev/random | fold -w 5 | head -n 1)"

usage() {
    echo "usage:"
    echo "  scr [option]"
    echo "options:"
    echo "  -f    full screenshot"
    echo "  -w    window screenshot"
    echo "  -s    selection screenshot"
}

while getopts fws option
do
    case $option in
        f)
            import -window root "$scr_path/$output.png"
            ;;
        w)
            import -window "$(xdotool getwindowfocus)" "$scr_path/$output.png"
            ;;
        s)
	        import "$scr_path/$output.png"
            ;;
        * | ?)
            usage
            exit;;
        esac
done

if [ $OPTIND -eq 1 ]; then
    echo "scr: missing argument"
    usage
    exit
fi


xclip -selection clipboard -t image/png -i "$scr_path/$output.png"
cp "$scr_path/$output.png" "$scr_path/latest.png"