Created
February 11, 2025 17:35
-
-
Save simonewebdesign/8e85e9fc86e0d53748f92adf7caa647d to your computer and use it in GitHub Desktop.
Simple pomodoro timer Bash script (macOS)
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 | |
# Function to send a macOS notification | |
send_notification() { | |
osascript -e 'display notification "'"$1"'" with title "'"$2"'"' | |
} | |
# Function to display a countdown in the terminal | |
countdown_timer() { | |
local time_left=$1 | |
local phase=$2 | |
while [ $time_left -gt 0 ]; do | |
# Display remaining time in the terminal | |
echo -ne "$phase Timer: $((time_left / 60))m $((time_left % 60))s remaining\r" | |
sleep 1 | |
((time_left--)) | |
done | |
echo -ne "\n$phase Timer: Time's up!\n" | |
} | |
# Timer settings (Pomodoro: 25 minutes work and 5 minutes break) | |
WORK_TIME=25 | |
BREAK_TIME=5 | |
# Function to run the Pomodoro timer with countdown and notifications | |
pomodoro_timer() { | |
# echo "Starting Pomodoro timer for $WORK_TIME minutes..." | |
# Work timer countdown | |
countdown_timer $((WORK_TIME * 60)) "Work" | |
send_notification "Time's up! Take a break!" "Pomodoro Timer" | |
# Break timer countdown | |
echo "Starting break time for $BREAK_TIME minutes..." | |
countdown_timer $((BREAK_TIME * 60)) "Break" | |
send_notification "Break is over! Back to work!" "Pomodoro Timer" | |
} | |
# Start the Pomodoro timer | |
pomodoro_timer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment