-
Notifications
You must be signed in to change notification settings - Fork 0
/
music-pomodoro-timer.sh
executable file
·161 lines (152 loc) · 4.56 KB
/
music-pomodoro-timer.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#
# Usage:
# musicPomodoroTimer.sh
#
# Description:
# This is pomodoro timer made by bash.
# The feature is that you can keep playing BGM during breaks. This is better than an alarm.
# Please use it to create a pace for telework.
#
# Requirements:
# macOS Big Sur
#
# Auther:
# GitHub: @happy-se-life
#
## You can modify following constants.
#
# Timer in minutes
CONST_CONCENTRATION_TIME=25
CONST_SHORT_BREAK_TIME=5
CONST_LONG_BREAK_TIME=15
#
# Short break cycle
#
CONST_SHORT_BREAK_CYCLE=4
#
# Bckground music for break time.
# It supports music files that can be played with the afplay command.
#
CONST_BREAK_TIME_BGM_FILE="./air.mp3"
#
# Speaking words
#
if [ $LANG = "ja_JP.UTF-8" ] ; then
# Japanese
CONST_VOICE_READY_TO_WORK="準備はよろしいですか?作業名を入力してください。"
CONST_VOICE_START_TO_WORK="作業を初めてください。"
CONST_VOICE_STOP_TO_WORK="作業を終了してください。お疲れ様でした。"
CONST_VOICE_TAKE_SHORT_BREAK="少し休憩しましょう。BGMをお届けします。"
CONST_VOICE_STOP_SHORT_BREAK="休憩の時間が終了しました。"
CONST_VOICE_TAKE_LONG_BREAK="長めに休憩をしましょう。BGMをお届けします。"
CONST_VOICE_STOP_LONG_BREAK="休憩の時間が終了しました。"
CONST_VOICE_NOTICE_NEXT_BREAK="次回は長めの休憩です。"
else
# English
CONST_VOICE_READY_TO_WORK="Are you ready? Please enter the task name."
CONST_VOICE_START_TO_WORK="Start working."
CONST_VOICE_STOP_TO_WORK="Stop working. Thank you for your hard work."
CONST_VOICE_TAKE_SHORT_BREAK="Let's take a break. We will deliver BGM."
CONST_VOICE_STOP_SHORT_BREAK="The break time is over."
CONST_VOICE_TAKE_LONG_BREAK="Let's take a long break. We will deliver BGM."
CONST_VOICE_STOP_LONG_BREAK="The break time is over."
CONST_VOICE_NOTICE_NEXT_BREAK="Next time is a long break."
fi
#
## You cannot modify below.
#
max_concentration_time=$(($CONST_CONCENTRATION_TIME * 60))
max_short_break_time=$(($CONST_SHORT_BREAK_TIME * 60))
max_long_break_time=$(($CONST_LONG_BREAK_TIME * 60))
concentration_cycle=1
short_break_count=1
log_file=`date "+%Y%m%d_log.md"`
task_name=""
duration=0
if [ ! -f ${CONST_BREAK_TIME_BGM_FILE} ] ; then
echo -en "BGM not found. Exited.\n"
exit 1
fi
# Log writer as markdown
function write_log () {
if [ -z "${task_name}" ] ; then
# Termination while break time.
return
fi
if [ ! -f $log_file ] ; then
# Header
echo -en "| Date time | Task name | Duration |\n" > ${log_file}
echo -en "|:--------------------|:-----------------------------------------|---------:|\n" >> ${log_file}
# 2021/05/16 20:35:16 | 1234567890123456789012345678901234567890 3600
fi
# Body
printf "| %-19s | %-40s | %8d |\n" "`date "+%Y/%m/%d %H:%M:%S"`" "`echo ${task_name} | cut -c 1-40`" $duration >> ${log_file}
}
# TODO
trap "write_log; clear; cat ${log_file}; echo -en \"Stopped by user.\n\"; exit" SIGINT
# Play BGM
function play_bgm () {
bgm=0
remaining=$1
while :
do
st=`date "+%s"`
afplay -t $1 "${CONST_BREAK_TIME_BGM_FILE}"
ed=`date "+%s"`
bgm=$(($ed - $st))
remaining=$(($remaining - $bgm))
if [ $remaining -lt 5 ] ; then
break
fi
if [ $remaining -lt $bgm ] ; then
afplay -t $remaining "${CONST_BREAK_TIME_BGM_FILE}"
break
fi
done
}
# Main loop
while :
do
say ${CONST_VOICE_READY_TO_WORK}
sleep 1
echo -n "Enter task name: "
read task_name
# Start concentration time
say ${CONST_VOICE_START_TO_WORK}
concentration_time=0
for((i=0; i<$max_concentration_time; i++))
do
progress=$((($i + 1) * 100 / $max_concentration_time))
echo -en "\r${progress}%"
sleep 1
concentration_time=$(($concentration_time + 1))
duration=$(($concentration_time / 60))
done
say ${CONST_VOICE_STOP_TO_WORK}
write_log
# Init.
task_name=""
duration=0
echo -en "\n"
# Break time
if [ $short_break_count -lt $CONST_SHORT_BREAK_CYCLE ] ; then
# Short break
say ${CONST_VOICE_TAKE_SHORT_BREAK}
echo -en "Short break.\n"
play_bgm $max_short_break_time
say ${CONST_VOICE_STOP_SHORT_BREAK}
short_break_count=$(($short_break_count + 1))
else
# Long break
say ${CONST_VOICE_TAKE_LONG_BREAK}
echo -en "Long break.\n"
play_bgm $max_long_break_time
say ${CONST_VOICE_STOP_LONG_BREAK}
short_break_count=0
fi
if [ $short_break_count -eq $CONST_SHORT_BREAK_CYCLE ] ; then
say ${CONST_VOICE_NOTICE_NEXT_BREAK}
fi
concentration_cycle=$(($concentration_cycle + 1))
done