Guest
Public paste!

brandizzi

By: a guest | Nov 25th, 2009 | Syntax: Bash | Size: 2.13 KB | Hits: 86 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. #!/bin/sh
  2. # toomuch.sh - A pomodoro counter in shell script
  3. # Requires either zenity or kdialog. Also, command sleep should support
  4. # prefixes (e.g. 25m meaning 25 minutes).
  5. #
  6. # If you call without arguments, it assumes the common defaults: 25m of work,
  7. # 5m of rest, and after four pomodoros a rest of 15m. Also, you can configure
  8. # calling the script this way
  9. #
  10. #  toomuch.sh <work time> <rest time> <pomodoros until rest>  <longer rest time>
  11.  
  12. if [ "$1" = "--help" ]
  13. then
  14.     echo 'Usage:'
  15.     echo '  toomuch.sh <work time> <rest time> <pomodoros until rest>  <longer rest time>'
  16.     exit
  17. fi
  18.  
  19. # How many time spent working
  20. worktime=$1
  21. if [ -z "$worktime" ]
  22. then
  23.     worktime=25m
  24. fi
  25.  
  26. # How many time spent relaxing
  27. partytime=$2
  28. if [ -z "$partytime" ]
  29. then
  30.     partytime=5m
  31. fi
  32.  
  33. # How many pomodoros are needed for a longer rest?
  34. toomuchtomatoes=$3
  35. if [ -z "$toomuchtomatoes" ]
  36. then
  37.     toomuchtomatoes=4
  38. fi
  39.  
  40. # How many time spent in a longer rest
  41. megapartytime=$4
  42. if [ -z "$megapartytime" ]
  43. then
  44.     megapartytime=15m
  45. fi
  46.  
  47. # Application title
  48. title="Too much!"
  49. partymessage='Hora do descanso!'
  50. backtowork='Volte ao trabalho!'
  51. megapartymessage='Hora do descanso LONGO!'
  52.  
  53. # Which dialog application to use?
  54. if [ "$(zenity --help 2> /dev/null)"  ]
  55. then
  56.     # If present, we use zenity (GNOME)
  57.     dialog="zenity --info"
  58.     textoption="--text"
  59.     titleoption='--title'
  60. else
  61.     # Otherwise, we use kdialog (KDE)
  62.     dialog="kdialog"
  63.     textoption="--msgbox"
  64.     titleoption="--title"
  65. fi
  66.  
  67. while true
  68. do
  69.     # First, we work
  70.     $dialog $titleoption="$title" ${textoption}="$backtowork"
  71.     sleep $worktime
  72.     for i in $(seq 2 $toomuchtomatoes)
  73.     do
  74.         # Now, let us rest a bit...
  75.         $dialog $titleoption="$title" ${textoption}="$partymessage"
  76.             sleep $partytime
  77.             # And return to work!
  78.             $dialog $titleoption="$title" ${textoption}="$backtowork"
  79.         sleep $worktime
  80.     done
  81.     # Made it $toomuchtomatoes times, let us relax for a longer time...
  82.     $dialog $titleoption="$title" ${textoption}="$megapartymessage"
  83.     sleep $megapartytime
  84.     # ...and return to work!
  85. done