1bf14c1c058ab08971ba7b95d8cc2e268d2eb85d
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
6 # * left click seconds to reset main timer
7 # * right click seconds to disable minutes & half hours of main timer
8 # * left click minutes to reset 2nd timer.
9 # * right click minutes to disable 2nd timer
11 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
13 source /a
/bin
/errhandle
/err
27 if [[ /b
/data
/daystart
-ot /b
/data
/daystart-generated
&& $day_tmp ]]; then
30 day_tmp
=$
(cat /b
/data
/daystart
)
31 day_start_hour
=${day_tmp%??}
32 day_start_min
=${day_tmp: -2}
33 echo $day_start_hour > /b
/data
/daystart-generated
34 echo $day_start_min >> /b
/data
/daystart-generated
35 day_start
=$
(date -d $day_start_hour:$day_start_min +%s
)
36 # for after midnight but before the day start.
37 if (( day_start
> EPOCHSECONDS
)); then
38 day_start
=$
(date -d "$day_start_hour:$day_start_min yesterday" +%s
)
47 # if [[ $line ]]; then
48 # echo "line=$line" >>/tmp/t
54 case $
(echo "$json" | jq
-r .name
) in
56 case $
(echo "$json" | jq
-r .button
) in
67 case $
(echo "$json" | jq
-r .button
) in
80 time=$
((EPOCHSECONDS
- start
))
81 total_mins
=$
(( time / 60 ))
82 mins
=$
(( total_mins
% 30 ))
83 half_hours
=$
(( total_mins
/ 30 ))
90 if [[ $start2 ]]; then
91 time2
=$
((EPOCHSECONDS
- start2
))
92 total_mins2
=$
(( time2
/ 60 ))
93 mins2
=$
(( total_mins2
% 30 ))
94 half_hours2
=$
(( total_mins2
/ 30 ))
95 # this is duplicate of mins and half hours except for different
96 # colors and looking at vars above.
99 printf '{ "color": "#EFC93E", "full_text": "'
100 for ((i
=half_hours2-1
; i
>= 0 ; i--
)); do
102 if (( i
> 0 && i
% 2 == 0 )); then
110 printf '{ "name":"mins2", "color":"#ED297D", "full_text": "'
111 for ((i
=29; i
>= 0 ; i--
)); do
112 if (( i
< mins2
)); then
117 if (( i
> 0 && i
% 5 == 0 )); then
127 printf '{ "color": "#FFB542", "full_text": "'
128 for ((i
=half_hours-1
; i
>= 0 ; i--
)); do
130 if (( i
> 0 && i
% 2 == 0 )); then
138 printf '{ "name":"mins", "color":"#0D6BDD", "full_text": "'
139 for ((i
=29; i
>= 0 ; i--
)); do
140 if (( i
< mins
)); then
145 if (( i
> 0 && i
% 5 == 0 )); then
153 printf '{ "name": "seconds", "full_text": "'
155 for ((i
=0; i
< 20; i
++)); do
156 # This first condition is to make the transition from full to empty
157 # be less jarring. We are filling a bucket of space with ticks of
158 # time, we would have to choose to show full or empty, but never
159 # both. Or we could have a half/tick to show full then empty real
160 # quick. I decided to try having it work like a snake, empty out the
161 # 1st quarter as we fill up the last quarter.
163 if (( i
> 0 && i
% 5 == 0 )); then
166 i_end
=$
(( time % 60 / 3 + 1 ))
167 if (( i_end
- i
> 15 )); then
169 elif (( i
< i_end
)); then
177 ## begin day percent, in thousandths, plus a spark block for ten_thousandth.
178 printf '{ "name": "day_percent", "full_text": "'
181 # after 24 hours, reset the day start
182 if (( day_start
+ 24 * 60 * 60 < EPOCHSECONDS
)); then
183 day_start
=$
(date -d $day_start_hour:$day_start_min +%s
)
186 spark_index
="$(( (100000 -($EPOCHSECONDS - $day_start)*100000 / (16*60*60) ) % 100 / 11 ))"
188 # note: 960 minutes, so 10 minutes is about 1%
189 day_thousandth
=$
(( 1000 - (EPOCHSECONDS
- day_start
)*1000 / (16*60*60) ))
190 printf %s
"$day_thousandth${spark:spark_index:1} $(date "+%l
:%M
")"
192 # .1% of a waking year is ~5.75 hours, or 365 thousandths of a day.
193 # 1% of a waking year is 3.7 days
194 # A spark line of a thousandth of a waking year is 39 minutes.
195 year_start
=$
(date +%s
-d 'january 1 6am')
196 year_days
=$
(( (EPOCHSECONDS
- year_start
) / (24*60*60) ))
197 year_start
=$
(( year_start
+ year_days
* 8*60*60 ))
198 year_spark_index
=$
(( ( 100000 - (EPOCHSECONDS
- year_start
)*100000 / (365*16*60*60) ) % 100 / 11 ))
199 year_tenthousandth
=$
(( 10000 - (EPOCHSECONDS
- year_start
)*10000 / (365*16*60*60) ))
200 printf %s
" $year_tenthousandth${spark:year_spark_index:1}"
209 # pass any arg and we just run once. mainly for debugging
214 #echo date -d $day_start_hour:$day_start_min +%s
215 #echo day_start=$day_start now=$EPOCHSECONDS
218 printf '{ "version": 1, "click_events": true }\n['
222 read -r -t 3 line ||
: