Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Created February 11, 2025 17:35
Show Gist options
  • Select an option

  • Save simonewebdesign/8e85e9fc86e0d53748f92adf7caa647d to your computer and use it in GitHub Desktop.

Select an option

Save simonewebdesign/8e85e9fc86e0d53748f92adf7caa647d to your computer and use it in GitHub Desktop.

Revisions

  1. simonewebdesign created this gist Feb 11, 2025.
    41 changes: 41 additions & 0 deletions pomodoro_timer.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/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