├── README.md ├── LICENSE └── music-pomodoro-timer.sh /README.md: -------------------------------------------------------------------------------- 1 | # music-pomodoro-timer 2 | This is pomodoro timer made by only bash for macOS. 3 | 4 | ## What's new 5 | * Changed the log format to markdown. 6 | * Now traps Ctrl + C. 7 | 8 | ## Features 9 | * You can keep playing BGM during breaks. This is better than an alarm only. 10 | * Audio guide. 11 | * Task logging. 12 | 13 | ## Requirements: 14 | * macOS Big Sur 15 | 16 | ## Install 17 | 18 | 1. Create install folder and change directory to that. 19 | 20 | 2. Clone the code. 21 |
22 | git clone https://github.com/happy-se-life/music-pomodoro-timer.git
23 | 
24 | 25 | 3. Grant execute permission. 26 |
27 | chmod +x ./music-pomodoro-timer.sh
28 | 
29 | 30 | 4. Set BGM file 31 |
32 | vim music-pomodoro-timer.sh
33 | 
34 | Edit CONST_BREAK_TIME_BGM_FILE="/pathto/xxxx.mp3". 35 | 36 | 5. Run it. 37 |
38 | ./music-pomodoro-timer.sh
39 | 
40 | 41 | ## License 42 | * MIT Lisense 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 happy-se-life 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /music-pomodoro-timer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Usage: 4 | # musicPomodoroTimer.sh 5 | # 6 | # Description: 7 | # This is pomodoro timer made by bash. 8 | # The feature is that you can keep playing BGM during breaks. This is better than an alarm. 9 | # Please use it to create a pace for telework. 10 | # 11 | # Requirements: 12 | # macOS Big Sur 13 | # 14 | # Auther: 15 | # GitHub: @happy-se-life 16 | # 17 | ## You can modify following constants. 18 | # 19 | # Timer in minutes 20 | CONST_CONCENTRATION_TIME=25 21 | CONST_SHORT_BREAK_TIME=5 22 | CONST_LONG_BREAK_TIME=15 23 | # 24 | # Short break cycle 25 | # 26 | CONST_SHORT_BREAK_CYCLE=4 27 | # 28 | # Bckground music for break time. 29 | # It supports music files that can be played with the afplay command. 30 | # 31 | CONST_BREAK_TIME_BGM_FILE="./air.mp3" 32 | # 33 | # Speaking words 34 | # 35 | if [ $LANG = "ja_JP.UTF-8" ] ; then 36 | # Japanese 37 | CONST_VOICE_READY_TO_WORK="準備はよろしいですか?作業名を入力してください。" 38 | CONST_VOICE_START_TO_WORK="作業を初めてください。" 39 | CONST_VOICE_STOP_TO_WORK="作業を終了してください。お疲れ様でした。" 40 | CONST_VOICE_TAKE_SHORT_BREAK="少し休憩しましょう。BGMをお届けします。" 41 | CONST_VOICE_STOP_SHORT_BREAK="休憩の時間が終了しました。" 42 | CONST_VOICE_TAKE_LONG_BREAK="長めに休憩をしましょう。BGMをお届けします。" 43 | CONST_VOICE_STOP_LONG_BREAK="休憩の時間が終了しました。" 44 | CONST_VOICE_NOTICE_NEXT_BREAK="次回は長めの休憩です。" 45 | else 46 | # English 47 | CONST_VOICE_READY_TO_WORK="Are you ready? Please enter the task name." 48 | CONST_VOICE_START_TO_WORK="Start working." 49 | CONST_VOICE_STOP_TO_WORK="Stop working. Thank you for your hard work." 50 | CONST_VOICE_TAKE_SHORT_BREAK="Let's take a break. We will deliver BGM." 51 | CONST_VOICE_STOP_SHORT_BREAK="The break time is over." 52 | CONST_VOICE_TAKE_LONG_BREAK="Let's take a long break. We will deliver BGM." 53 | CONST_VOICE_STOP_LONG_BREAK="The break time is over." 54 | CONST_VOICE_NOTICE_NEXT_BREAK="Next time is a long break." 55 | fi 56 | # 57 | ## You cannot modify below. 58 | # 59 | max_concentration_time=$(($CONST_CONCENTRATION_TIME * 60)) 60 | max_short_break_time=$(($CONST_SHORT_BREAK_TIME * 60)) 61 | max_long_break_time=$(($CONST_LONG_BREAK_TIME * 60)) 62 | concentration_cycle=1 63 | short_break_count=1 64 | log_file=`date "+%Y%m%d_log.md"` 65 | task_name="" 66 | duration=0 67 | 68 | if [ ! -f ${CONST_BREAK_TIME_BGM_FILE} ] ; then 69 | echo -en "BGM not found. Exited.\n" 70 | exit 1 71 | fi 72 | 73 | # Log writer as markdown 74 | function write_log () { 75 | if [ -z "${task_name}" ] ; then 76 | # Termination while break time. 77 | return 78 | fi 79 | if [ ! -f $log_file ] ; then 80 | # Header 81 | echo -en "| Date time | Task name | Duration |\n" > ${log_file} 82 | echo -en "|:--------------------|:-----------------------------------------|---------:|\n" >> ${log_file} 83 | # 2021/05/16 20:35:16 | 1234567890123456789012345678901234567890 3600 84 | fi 85 | # Body 86 | printf "| %-19s | %-40s | %8d |\n" "`date "+%Y/%m/%d %H:%M:%S"`" "`echo ${task_name} | cut -c 1-40`" $duration >> ${log_file} 87 | } 88 | 89 | # TODO 90 | trap "write_log; clear; cat ${log_file}; echo -en \"Stopped by user.\n\"; exit" SIGINT 91 | 92 | # Play BGM 93 | function play_bgm () { 94 | bgm=0 95 | remaining=$1 96 | while : 97 | do 98 | st=`date "+%s"` 99 | afplay -t $1 "${CONST_BREAK_TIME_BGM_FILE}" 100 | ed=`date "+%s"` 101 | bgm=$(($ed - $st)) 102 | remaining=$(($remaining - $bgm)) 103 | if [ $remaining -lt 5 ] ; then 104 | break 105 | fi 106 | if [ $remaining -lt $bgm ] ; then 107 | afplay -t $remaining "${CONST_BREAK_TIME_BGM_FILE}" 108 | break 109 | fi 110 | done 111 | } 112 | 113 | # Main loop 114 | while : 115 | do 116 | say ${CONST_VOICE_READY_TO_WORK} 117 | sleep 1 118 | echo -n "Enter task name: " 119 | read task_name 120 | 121 | # Start concentration time 122 | say ${CONST_VOICE_START_TO_WORK} 123 | concentration_time=0 124 | for((i=0; i<$max_concentration_time; i++)) 125 | do 126 | progress=$((($i + 1) * 100 / $max_concentration_time)) 127 | echo -en "\r${progress}%" 128 | sleep 1 129 | concentration_time=$(($concentration_time + 1)) 130 | duration=$(($concentration_time / 60)) 131 | done 132 | say ${CONST_VOICE_STOP_TO_WORK} 133 | write_log 134 | 135 | # Init. 136 | task_name="" 137 | duration=0 138 | echo -en "\n" 139 | 140 | # Break time 141 | if [ $short_break_count -lt $CONST_SHORT_BREAK_CYCLE ] ; then 142 | # Short break 143 | say ${CONST_VOICE_TAKE_SHORT_BREAK} 144 | echo -en "Short break.\n" 145 | play_bgm $max_short_break_time 146 | say ${CONST_VOICE_STOP_SHORT_BREAK} 147 | short_break_count=$(($short_break_count + 1)) 148 | else 149 | # Long break 150 | say ${CONST_VOICE_TAKE_LONG_BREAK} 151 | echo -en "Long break.\n" 152 | play_bgm $max_long_break_time 153 | say ${CONST_VOICE_STOP_LONG_BREAK} 154 | short_break_count=0 155 | fi 156 | if [ $short_break_count -eq $CONST_SHORT_BREAK_CYCLE ] ; then 157 | say ${CONST_VOICE_NOTICE_NEXT_BREAK} 158 | fi 159 | 160 | concentration_cycle=$(($concentration_cycle + 1)) 161 | done 162 | --------------------------------------------------------------------------------