#!/usr/bin/env bash

# requires:
# https://github.com/lolilolicon/xrectsel.git
# festival(1) text to speech system (just because)

# Default time:
BYZANZ_DURATION=8

args=$(getopt -uo 'hvri:t:o:b:u:' -- $*)
[ $? != 0 ] && print_help
set -- $args

for i
do
    case "$i"
    in
        -t)
            BYZANZ_DURATION="$2"
            shift
            shift
            ;;
    esac
done

eval `xrectsel "BYZANZ_X=%x; BYZANZ_Y=%y; BYZANZ_WIDTH=%w; BYZANZ_HEIGHT=%h"`
echo "recording for $BYZANZ_DURATION seconds in three. two. one. GO!" | festival --tts
byzanz-record -x $BYZANZ_X -y $BYZANZ_Y --delay=0 -d $BYZANZ_DURATION -h $BYZANZ_HEIGHT -w $BYZANZ_WIDTH ~/screenshots/screencast-`date +"%Y-%m-%d-%T"`.gif
echo 'finished recording' | festival --tts