Skip to content

Instantly share code, notes, and snippets.

@gpanders
Last active June 16, 2020 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpanders/81d1428e10cc1477888ebf49e360a7fb to your computer and use it in GitHub Desktop.
Save gpanders/81d1428e10cc1477888ebf49e360a7fb to your computer and use it in GitHub Desktop.
Command line Pomodoro timer
#!/bin/sh
usage() {
echo "Usage: $(basename "$0") [focus time] [short break] [long break]"
}
if [ "$1" = "-h" ]; then
usage
exit 0
fi
focus_time=${1:-25}
short_break=${2:-5}
long_break=${3:-15}
# Ensure all arguments are numbers
case $focus_time$short_break$long_break in
*[!0-9]*)
echo "Arguments must be positive integer numbers" >&2
usage >&2
exit 1
;;
esac
notify() {
echo "$1"
if command -v terminal-notifier >/dev/null 2>&1; then
terminal-notifier -title 'Pomodoro' -message "$1"
elif command -v notify-send >/dev/null 2>&1; then
notify-send Pomodoro "$1"
fi
}
countdown() {
timer=$(($1 * 60))
while true; do
minutes=$((timer / 60))
seconds=$((timer - 60*minutes))
printf '\e[0K\r' # Clear current line
printf 'Remaining: %02d:%02d' "$minutes" "$seconds"
[ $timer -eq 0 ] && break
timer=$((timer - 1))
sleep 1
done
printf '\n'
}
while true; do
notify "Focus for $focus_time minutes"
countdown "$focus_time"
notify "Take a short break for $short_break minutes (1/4)"
countdown "$short_break"
notify "Focus for $focus_time minutes"
countdown "$focus_time"
notify "Take a short break for $short_break minutes (2/4)"
countdown "$short_break"
notify "Focus for $focus_time minutes"
countdown "$focus_time"
notify "Take a short break for $short_break minutes (3/4)"
countdown "$short_break"
notify "Focus for $focus_time minutes"
countdown "$focus_time"
notify "Take a long break for $long_break minutes (4/4)"
countdown "$long_break"
done

Installation

wget -o ~/.local/bin/pomodoro https://gist.githubusercontent.com/gpanders/81d1428e10cc1477888ebf49e360a7fb/raw/2e531dba1723b4f1a568b93d23400bbfaced1b08/pomodoro.sh
chmod +x ~/.local/bin/pomodoro

Obviously you can install it anywhere you like, just make sure the installation directory is on your PATH.

Usage

pomodoro [FOCUS_TIME] [SHORT_BREAK] [LONG_BREAK]

The default values are 25 for FOCUS_TIME, 5 for SHORT_BREAK, and 15 for LONG_BREAK. All units are in minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment