forked from jsspencer/pomo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcowsay_status.sh
executable file
·141 lines (111 loc) · 3.89 KB
/
cowsay_status.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# ╒══════════════════════════════════════════════════════════╕
# Variables
# ╘══════════════════════════════════════════════════════════╛
PATH_TO_POMO_SCRIPT=~/Programs/pomo_termux/pomo.sh
COWSAY_FILE=~/Programs/pomo_termux/tutoro.cow
export POMO_WORK_TIME=25
export POMO_BREAK_TIME=5
POMOS_PER_CYCLE=4
# ╒══════════════════════════════════════════════════════════╕
# Utility functions
# ╘══════════════════════════════════════════════════════════╛
function cleanup() {
tput cnorm
clear
}
function init_tgui() {
clear
toilet -f ivrit --gay "Pomo"
echo "Current task: "
echo "----------------"
echo " $1"
echo -e "\n\n\n\n"
trap cleanup EXIT # Redraw cursor when exiting
tput civis
}
function notify() {
termux-vibrate -d 1000 &&
termux-tts-speak "$1" &&
termux-notification -t "Pomodoro" -c "$1" --prio high
}
function exit_pomodoro() {
notify "Exiting pomodoro"
$PATH_TO_POMO_SCRIPT stop
clear
exit
}
function get_current_status() {
if [ "$1" == "W" ]; then
echo "Work "
elif [ "$1" == "B" ]; then
echo "Break"
else
echo "Unknown status: $short_status"
fi
}
function draw_status() {
echo "Pomodoro: $counter_pomodoros / $POMOS_PER_CYCLE"
echo -e "Status: $current_status \n"
echo "$time_left" | cowthink -f $COWSAY_FILE
}
function select_task() {
notify "Please select a task."
echo "Select a task:"
read -r TASK
if [ -z "$TASK" ]; then
TASK="No task selected"
fi
}
function switch_from_break_to_work() {
notify "The Break is over, select a new task"
# Pause the timer so the user can select a new task
$PATH_TO_POMO_SCRIPT pause
cleanup
select_task
counter_pomodoros=$((counter_pomodoros+1))
notify "Starting pomo cycle $counter_pomodoros for:$TASK"
init_tgui "$TASK"
# Restart the timer
$PATH_TO_POMO_SCRIPT pause
}
function switch_from_work_to_break() {
if [ $counter_pomodoros -eq "$POMOS_PER_CYCLE" ]; then
notify "Long break starts now. Bye!"
exit_pomodoro
else
notify "The work is over, take a short break"
fi
}
# ╒══════════════════════════════════════════════════════════╕
# Main Loop
# ╘══════════════════════════════════════════════════════════╛
counter_seconds=0
counter_pomodoros=1
old_short_status="W"
select_task
$PATH_TO_POMO_SCRIPT start
notify "Starting pomodoro for task: $TASK"
init_tgui "$TASK"
while true; do
# Redraw the whole screen every 30 seconds
counter_seconds=$((counter_seconds+1))
if [ $counter_seconds -eq 30 ]; then
init_tgui "$TASK"
counter_seconds=0
fi
pomodoro_clock=$($PATH_TO_POMO_SCRIPT clock)
short_status="${pomodoro_clock:1:1}"
time_left="${pomodoro_clock:2:6}"
current_status=$(get_current_status "$short_status")
tput sc # Save cursor position
draw_status
tput rc # Restore cursor position -> Redraws only one line
sleep 1
if [ "$short_status" == "W" ] && [ "$old_short_status" == "B" ]; then
switch_from_break_to_work
elif [ "$short_status" == "B" ] && [ "$old_short_status" == "W" ]; then
switch_from_work_to_break
fi
old_short_status=$short_status
done