Last active
September 7, 2019 15:11
-
-
Save kcivey/0e752824a9886213c70b849e020cc13c to your computer and use it in GitHub Desktop.
Pomodoro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run for Pomodoro timer. Defaults to 25 min session and 5 minute break. | |
# Set $QUIET environment variable to eliminate the countdown output. | |
# I run it with a gnome-terminal profile called "pomodoro" where I have | |
# the text size set to 72 pt, with text and background colors adjusted, | |
# starting it like this: | |
# | |
# gnome-terminal --window-with-profile pomodoro --hide-menubar -- \ | |
# sh -c "setterm -cursor off; resize -s 1 7; pomodoro $1 $2" | |
WORK_TIME=$(( ${1:-25} * 60 )) | |
BREAK_TIME=$(( ${2:-5} * 60 )) | |
WARNING_INTERVAL=30; | |
END_OF_WORK_SOUND=~/.local/share/sounds/job-done.ogg | |
END_OF_BREAK_SOUND=~/.local/share/sounds/vuvuzela-trumpet.ogg | |
function countdown { | |
COUNTER=$1 | |
while [ $COUNTER -gt 0 ]; do | |
if [ -z "$QUIET" ]; then | |
printf ' %02d:%02d \r' $(( $COUNTER / 60 )) $(( $COUNTER % 60 )) | |
fi | |
sleep 1 | |
let COUNTER-=1 | |
done | |
printf '\033[5m 00:00 \033[0m\r' # blinking zero | |
} | |
function run_period { | |
TIME=$1 | |
SOUND=$2 | |
MESSAGE=$3 | |
countdown $TIME | |
while true; do paplay $SOUND; sleep $WARNING_INTERVAL; done & | |
WARNING_PID=$! | |
zenity --warning --text="$MESSAGE" | |
kill $WARNING_PID | |
} | |
while true; do | |
run_period $WORK_TIME $END_OF_WORK_SOUND \ | |
"Work session has ended. Take a $(( $BREAK_TIME / 60)) minute break" | |
run_period $BREAK_TIME $END_OF_BREAK_SOUND "Break is over" | |
done 2> >(grep -v 'GtkDialog\|No such process' >&2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment