Advertisement
howtophil

Pomodoro Timer (Bash/Terminal)

Jul 3rd, 2018
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.68 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #------------------------------------------------
  4. #
  5. # A simple Pomodoro method timer in bash
  6. # Uses espeak to announce Work/Break/Long-Break
  7. #
  8. # ./pomodoro.sh
  9. #
  10. # Hope you ejoy,
  11. #    Phillip J Rhoades
  12. #
  13. #------------------------------------------------
  14.  
  15. #Times
  16. workminutes=25 #working pomodoro minutes
  17. shortbreak=5 #short break minutes
  18. longbreak=15 #long break minutes
  19. pommax=4 #Work pomodoros before long break
  20.  
  21. #Initializing
  22. pomcount=0
  23. thebreak=0
  24. sbreaker=0
  25.  
  26. #Sounds
  27. sbsound="/usr/share/sounds/purple/receive.wav"
  28. lbsound="/usr/share/sounds/speech-dispatcher/test.wav"
  29. wksound="/usr/share/xdx/sounds/attention.wav"
  30.  
  31. ###
  32.  
  33. tput civis #hide the cursor
  34.  
  35. #Bring the cursor back after ctrl-c
  36. trap ctrl_c INT
  37. function ctrl_c() {
  38.         tput cvvis
  39.     exit
  40. }
  41.  
  42. #Loop those pomodoros
  43. while [ 1 ]; do
  44.     if [ $sbreaker -eq 1 ] && [ $pomcount -ne $pommax  ]; then
  45.         let "sbreaker=0"
  46.         dominutes=$shortbreak
  47.         theword="SHORT BREAK:"
  48.         thesound="$sbsound"
  49.     else
  50.         if [ $pomcount -eq $pommax ]; then
  51.             let "pomcount=0"
  52.             dominutes=$longbreak
  53.             theword="LONG BREAK:"
  54.             thesound="$lbsound"
  55.             let "sbreaker=0"
  56.         else
  57.             let "pomcount+=1"
  58.             dominutes=$workminutes
  59.             theword="WORK $pomcount:"
  60.             thesound="$wksound"
  61.             let "sbreaker=1"
  62.         fi
  63.     fi
  64.  
  65.     #echo "$pomcount | $thebreak | $dominutes"
  66.    
  67.     secs=$(($dominutes * 60))
  68.     echo $theword |espeak &>/dev/null
  69.     while [ $secs -gt 0 ]; do
  70.         #echo -ne "$theword $secs\033[0K\r"
  71.         theminutes=$(printf "%02d" $((m=(${secs}%3600)/60)))
  72.         theseconds=$(printf "%02d" $((s=${secs}%60)))
  73.         echo -ne "$theword $theminutes:$theseconds\033[0K\r"
  74.         sleep 1
  75.         : $((secs--))
  76.     done
  77.     #play "$thesound" &>/dev/null
  78. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement