Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Run for Pomodoro timer. Defaults to 25 min session and 5 minute break.
  4. # Set $QUIET environment variable to eliminate the countdown output.
  5. # I run it with a gnome-terminal profile called "pomodoro" where I have
  6. # the text size set to 72 pt, with text and background colors adjusted,
  7. # starting it like this:
  8. #
  9. # gnome-terminal --window-with-profile pomodoro --hide-menubar -- \
  10. # sh -c "setterm -cursor off; resize -s 1 7; pomodoro $1 $2"
  11.  
  12. WORK_TIME=$(( ${1:-25} * 60 ))
  13. BREAK_TIME=$(( ${2:-5} * 60 ))
  14. WARNING_INTERVAL=30;
  15. END_OF_WORK_SOUND=~/.local/share/sounds/job-done.ogg
  16. END_OF_BREAK_SOUND=~/.local/share/sounds/vuvuzela-trumpet.ogg
  17.  
  18. function countdown {
  19. COUNTER=$1
  20. while [ $COUNTER -gt 0 ]; do
  21. if [ -z "$QUIET" ]; then
  22. printf ' %02d:%02d \r' $(( $COUNTER / 60 )) $(( $COUNTER % 60 ))
  23. fi
  24. sleep 1
  25. let COUNTER-=1
  26. done
  27. printf '\033[5m 00:00 \033[0m\r' # blinking zero
  28. }
  29.  
  30. function run_period {
  31. TIME=$1
  32. SOUND=$2
  33. MESSAGE=$3
  34. countdown $TIME
  35. while true; do paplay $SOUND; sleep $WARNING_INTERVAL; done &
  36. WARNING_PID=$!
  37. zenity --warning --text="$MESSAGE"
  38. kill $WARNING_PID
  39. }
  40.  
  41. while true; do
  42. run_period $WORK_TIME $END_OF_WORK_SOUND \
  43. "Work session has ended. Take a $(( $BREAK_TIME / 60)) minute break"
  44. run_period $BREAK_TIME $END_OF_BREAK_SOUND "Break is over"
  45. done 2> >(grep -v 'GtkDialog\|No such process' >&2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement