at master 1.6 kB view raw
1#!/usr/bin/bash 2# credits: https://github.com/gpanders/dotfiles/blob/master/.local/bin/pomodoro 3 4usage() { 5 echo "Usage: $(basename "$0") [focus time] [short break] [long break]" 6} 7 8if [ "$1" = "-h" ]; then 9 usage 10 exit 0 11fi 12 13focus_time=${1:-25} 14short_break=${2:-5} 15long_break=${3:-15} 16 17# Ensure all arguments are numbers 18case $focus_time$short_break$long_break in 19 *[!0-9]*) 20 echo "Arguments must be positive integer numbers" >&2 21 usage >&2 22 exit 1 23 ;; 24esac 25 26notify() { 27 echo "$1" 28 if command -v terminal-notifier >/dev/null 2>&1; then 29 terminal-notifier -title 'Pomodoro' -message "$1" 30 elif command -v notify-send >/dev/null 2>&1; then 31 notify-send "$1" 32 fi 33} 34 35countdown() { 36 timer=$(($1 * 60)) 37 while true; do 38 minutes=$((timer / 60)) 39 seconds=$((timer - 60*minutes)) 40 printf '\e[0K\r' # Clear current line 41 printf 'Remaining: %02d:%02d' "$minutes" "$seconds" 42 43 [ $timer -eq 0 ] && break 44 timer=$((timer - 1)) 45 sleep 1 46 done 47 printf '\n' 48} 49 50while true; do 51 notify "Focus for $focus_time minutes" 52 countdown "$focus_time" 53 54 notify "Take a short break for $short_break minutes (1/4)" 55 countdown "$short_break" 56 57 notify "Focus for $focus_time minutes" 58 countdown "$focus_time" 59 60 notify "Take a short break for $short_break minutes (2/4)" 61 countdown "$short_break" 62 63 notify "Focus for $focus_time minutes" 64 countdown "$focus_time" 65 66 notify "Take a short break for $short_break minutes (3/4)" 67 countdown "$short_break" 68 69 notify "Focus for $focus_time minutes" 70 countdown "$focus_time" 71 72 notify "Take a long break for $long_break minutes (4/4)" 73 countdown "$long_break" 74done