#!/bin/bash
NAME="/tmp/$(date +%Y%m%d_%H%M%S).gif"
DEFAULT_DURATION=10
DURATION=10
echo "Select capture area" | xcowsay -t 1
AREA="$(xrectsel)"
IFS=+ read DIM X Y <<< $AREA
IFS=x read W H <<< $DIM
echo ""
#read -p "Enter recording duration in seconds: " USERDUR
# Duration and output file
#if [ $USERDUR -gt 0 ]; then
#DURATION=$USERDUR
#else
#DURATION=$DEFAULT_DURATION
#fi
echo "$DURATION sec. Recording has started..." | xcowsay -t 1
byzanz-record --cursor --duration=$DURATION --x=$X --y=$Y --width=$W --height=$H "$NAME"
#echo -e "Recording finished\n$NAME" | xcowsay -t 1
if [ -f "$NAME" ]; then
# Open file in defaul viewer
xdg-open "$NAME"
# xviewer /tmp/"$NAME"
fi