#!/bin/sh

work='Do some work now, you lazy';
rest="Have a rest, AWAY from the accursed computer!"
stop="Time to STOP: sleep before 1am"
yes="OOSU!"  # "Yes, Sir."
naggish=60
bedtime=1
waketime=7

insults="prat
wazzock
pillock
prawn
muppet
knobhead
tosser
git
jackass
putz
dope
nimrod
tool
scumbag
dork
freak
dweeb
lump
tonker
chuckle-head
numbskull
sninky-ponk
doofus
tally-wacker
muffin-head
numpty
"

message() {
	while true; do
        xmessage -buttons "$yes:8" -timeout $naggish "$*"
        case $? in
        8) break ;;
        0) : ;;
        *) echo >&2 xrest: message failed ; exit 1 ;;
        esac
    done
}

delay() {
    hour=`date +%H`
    if [ $bedtime -ge $waketime -a $hour -ge $bedtime ]; then
        stop
    fi
    if [ $bedtime -lt $waketime -a $hour -ge $bedtime -a $hour -lt $waketime ]; then
        stop
    fi
    sleep $(( $1 * 60 ))
}

work() {
    delay=$1
    insult=`echo -n "$insults" | shuf | head -n1`  # a proper fortune command would be better
    message "$work $insult!"
    delay $delay
}

rest() {
    delay=$1
    message "$rest  $delay minutes."
    delay $delay
}

stop() {
    message "$stop"
    exit 0
}

work3() {
    work 25
    rest 5
    work 25
    rest 5
    work 25
}

work4() {
    work3
    rest 5
    work 25
}

work3
rest 15
work4
rest 20
work4
rest 15
work4
stop
