-
Notifications
You must be signed in to change notification settings - Fork 0
/
pomo
executable file
·83 lines (74 loc) · 1.9 KB
/
pomo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Pomodoro durations
POMODORO_DURATION=25 # Pomodoro work duration in minutes
SHORT_BREAK=5 # Short break duration in minutes
LONG_BREAK=15 # Long break duration in minutes
TOMATO="🍅"
# Initialize variables
TIME_REMAINING=$((POMODORO_DURATION * 60))
PAUSED=0
RUNNING=0
# Function to display the timer
display_timer() {
clear
local mins=$((TIME_REMAINING / 60))
local secs=$((TIME_REMAINING % 60))
echo -e "\n$message\n\nTime remaining: $(printf "%02d:%02d" $mins $secs)"
echo -e "\nPress 'p' to pause, 'r' to resume, 'q' to quit."
}
# Function to countdown
countdown() {
local duration=$1
message=$2
TIME_REMAINING=$((duration * 60))
RUNNING=1
while [ $TIME_REMAINING -gt 0 ]; do
if [ $PAUSED -eq 0 ] && [ $RUNNING -eq 1 ]; then
display_timer
sleep 1
TIME_REMAINING=$((TIME_REMAINING - 1))
fi
read -rsn1 -t 1 key
if [[ "$key" == "p" ]]; then
PAUSED=1
RUNNING=0
clear
echo -e "\nPaused. Press 'r' to resume or 'q' to quit."
elif [[ "$key" == "r" ]]; then
PAUSED=0
RUNNING=1
display_timer
elif [[ "$key" == "q" ]]; then
clear
echo "Exiting..."
exit 0
fi
done
}
# Main loop
while true; do
clear
echo -e "Pomodoro Timer $TOMATO\n"
echo "1) Start Pomodoro"
echo "2) Short Break"
echo "3) Long Break"
echo "4) Exit"
echo -n "Choose an option: "
read -rsn1 choice
case $choice in
1)
countdown $POMODORO_DURATION "Work session"
;;
2)
countdown $SHORT_BREAK "Short break"
;;
3)
countdown $LONG_BREAK "Long break"
;;
4)
clear
echo "Exiting..."
exit 0
;;
esac
done