You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.9 KiB

  1. #!/bin/sh
  2. sl=25 # study session time in minutes
  3. bl=5 # break time in minutes
  4. bll=20 # long break time in minutes
  5. bls=4 # number of study sessions before long break
  6. ringtone="$HOME/Media/warcraft-soundtrack/2004 World of Warcraft/ringtone.flac"
  7. sessions=0 # number of sessions passed
  8. # if you kill and restart pomodoro.sh, you can specify the number of sessions passed
  9. [ $# -gt 0 ] && sessions=$1
  10. printf "\rStudy time! Sessions done: %d\n" "$sessions"
  11. notify-send -i "media-playback-playing" "Study time!"
  12. start="$(date +%s)" # start time stamp
  13. state=0 # 0 - study, 1 - relax, 2 - long break
  14. tl=$sl # current time limit
  15. while :
  16. do
  17. now="$(date +%s)"
  18. left=$((tl * 60 - (now - start)))
  19. printf "\033[K\r%02d:%02d" "$((left / 60))" "$((left % 60))"
  20. if [ $left -le 0 ]; then
  21. printf "\033[1A\033[K"
  22. if [ $state -eq 0 ]; then
  23. sessions=$((sessions + 1))
  24. if [ $((sessions % bls)) -eq 0 ]; then
  25. state=2
  26. printf "\rLong break time! Sessions done: %d\n" "$sessions"
  27. notify-send -i "media-playback-paused" "Long break time!"
  28. mpv --no-vid --no-terminal "$ringtone" &
  29. tl=$bll
  30. else
  31. state=1
  32. printf "\rBreak time! Sessions done: %d\n" "$sessions"
  33. notify-send -i "media-playback-paused" "Break time!"
  34. mpv --no-vid --no-terminal "$ringtone" &
  35. tl=$bl
  36. fi
  37. else
  38. state=0
  39. printf "\rStudy time! Sessions done: %d\n" "$sessions"
  40. notify-send -i "media-playback-playing" "Study time!"
  41. mpv --no-vid --no-terminal "$ringtone" &
  42. tl=$sl
  43. fi
  44. mpvpid=$!
  45. printf "%s " "Press Enter to start the timer"
  46. read ans
  47. printf "\033[1A\033[K"
  48. start="$(date +%s)"
  49. kill $mpvpid 2> /dev/null
  50. fi
  51. sleep 1
  52. done