brandizzi
By: a guest | Nov 25th, 2009 | Syntax:
Bash | Size: 2.13 KB | Hits: 86 | Expires: Never
#!/bin/sh
# toomuch.sh - A pomodoro counter in shell script
# Requires either zenity or kdialog. Also, command sleep should support
# prefixes (e.g. 25m meaning 25 minutes).
#
# If you call without arguments, it assumes the common defaults: 25m of work,
# 5m of rest, and after four pomodoros a rest of 15m. Also, you can configure
# calling the script this way
#
# toomuch.sh <work time> <rest time> <pomodoros until rest> <longer rest time>
if [ "$1" = "--help" ]
then
echo 'Usage:'
echo ' toomuch.sh <work time> <rest time> <pomodoros until rest> <longer rest time>'
exit
fi
# How many time spent working
worktime=$1
if [ -z "$worktime" ]
then
worktime=25m
fi
# How many time spent relaxing
partytime=$2
if [ -z "$partytime" ]
then
partytime=5m
fi
# How many pomodoros are needed for a longer rest?
toomuchtomatoes=$3
if [ -z "$toomuchtomatoes" ]
then
toomuchtomatoes=4
fi
# How many time spent in a longer rest
megapartytime=$4
if [ -z "$megapartytime" ]
then
megapartytime=15m
fi
# Application title
title="Too much!"
partymessage='Hora do descanso!'
backtowork='Volte ao trabalho!'
megapartymessage='Hora do descanso LONGO!'
# Which dialog application to use?
if [ "$(zenity --help 2> /dev/null)" ]
then
# If present, we use zenity (GNOME)
dialog="zenity --info"
textoption="--text"
titleoption='--title'
else
# Otherwise, we use kdialog (KDE)
dialog="kdialog"
textoption="--msgbox"
titleoption="--title"
fi
while true
do
# First, we work
$dialog $titleoption="$title" ${textoption}="$backtowork"
sleep $worktime
for i in $(seq 2 $toomuchtomatoes)
do
# Now, let us rest a bit...
$dialog $titleoption="$title" ${textoption}="$partymessage"
sleep $partytime
# And return to work!
$dialog $titleoption="$title" ${textoption}="$backtowork"
sleep $worktime
done
# Made it $toomuchtomatoes times, let us relax for a longer time...
$dialog $titleoption="$title" ${textoption}="$megapartymessage"
sleep $megapartytime
# ...and return to work!
done