Skip to content

Instantly share code, notes, and snippets.

@bbassett
Created December 6, 2024 02:56
Show Gist options
  • Save bbassett/53ebf7b10b9eb9c3b648ea7534124d9a to your computer and use it in GitHub Desktop.
Save bbassett/53ebf7b10b9eb9c3b648ea7534124d9a to your computer and use it in GitHub Desktop.
Terminal Pomodoro
#!/bin/bash
################
# Installation #
################
# brew install figlet terminal-notifier
# wget -O ~/.local/bin/pomo https://gist.github.com/bbassett/53ebf7b10b9eb9c3b648ea7534124d9a
# chmod +x ~/.local/bin/pomo
# Timer durations in seconds
FOCUS_TIME=1500 # 25 minutes
SHORT_BREAK_TIME=300 # 5 minutes
LONG_BREAK_TIME=900 # 15 minutes
# Function to hide cursor, this prevents it from flashing in and out
hide_cursor() {
echo -e "\033[?25l"
}
# Function to show cursor - because you're going to want it back
show_cursor() {
echo -e "\033[?25h"
}
# when you hit ctrl+c - get cursor back then exit
trap 'show_cursor; exit' SIGINT
# Function to run a countdown timer
countdown() {
duration=$1
message=$2
for i in $(seq $duration -1 1); do
clear
minutes=$((i / 60))
seconds=$((i % 60))
echo -e "$(figlet -f univers -w 100 "$minutes:$(printf '%02d' $seconds)")"
sleep 1
done
# OS alert, so we don't have to stare at the terminal
terminal-notifier -title "Pomodoro" -message "$message" -sound "default"
}
# Loop through Pomodoro pattern
while true; do
hide_cursor
for session in 1 2 3 4; do
# Focus session
echo "Starting focus session ($session of 4)..."
countdown $FOCUS_TIME "Focus session complete!"
printf "\n"
read -p "Press <Enter> to start the next Pomodoro cycle or Ctrl+C to exit..."
# Break after each focus except the last
if [[ $session -lt 4 ]]; then
echo "Starting short break..."
countdown $SHORT_BREAK_TIME "Short break complete!"
printf "\n"
read -p "Press <Enter> to start the next Pomodoro cycle or Ctrl+C to exit..."
fi
done
# Long break after 4 focus sessions
echo "Starting long break..."
countdown $LONG_BREAK_TIME "Long break complete!"
printf "\n"
read -p "Press <Enter> to start the next Pomodoro cycle or Ctrl+C to exit..."
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment