Created
January 8, 2020 18:34
-
-
Save antonkatz/b1c2fd6628346d01ef6860a81478f3b9 to your computer and use it in GitHub Desktop.
This script turns watson into a pomodoro timer. It takes a single argument: time in minutes for the pomodoro sprint. The rest are passed to `watson start`. Once the timer is up, it activetes the shell in which it's running, and asks the user to press `Enter` to stop watson.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# getting the duration in minutes, and shifting the arguments, which will be all passed to watson | |
DURATION=$1 | |
shift | |
echo "Setting pomodoro for ${DURATION} minutes" | |
WINDOW_DECIMAL_ID=`xdotool getwindowfocus` | |
WINDOW_ID=`printf '0x%x\n' ${WINDOW_DECIMAL_ID}` | |
watson start "$@" | |
if [ "$?" = "0" ] | |
then | |
duration=`expr $DURATION \* 60` | |
start=`date '+%s'` | |
end=$(($start + $duration)) | |
current=$start | |
left=$(($end - $current)) | |
echo "Pomodoro ends at $(date -d@${end} +%H:%M:%S)" | |
while (($left > 0)); do | |
sleep 1 | |
current=`date '+%s'` | |
left=$(($end - $current)) | |
formattedTime=`date -d@${left} -u +%H:%M:%S` | |
printf "\e\r${formattedTime}" | |
done | |
wmctrl -i -a ${WINDOW_ID} | |
echo "" | |
read -p "Press enter to stop" | |
watson stop | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment