2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
7 # * left click seconds to reset & enable main timer which shows 30
8 # minutes in blue and half hours in orange.
10 # * right click seconds to disable minutes & half hours of main timer
12 # * left click minutes to reset & enable 2nd timer.
14 # * right click minutes to disable 2nd timer
18 # Sections from right to left.
20 # section #1, labeled day_percent
22 # 1. Thousandths of a 16 hour day left. 1 = 57.6 seconds.
23 # 2. Bar of one thousand of a day which gets shorter by ninths. One ninth is 6.4 seconds.
24 # 3. Start of the day (only the non-zero numbers). Set this with the ds command.
25 # 4. The time right now.
26 # 5. Ten thousands of the year left. 1 = 52:34 minutes (leap year = 52:42)
27 # 6. Bar of 1/10,000 of a year shrinking by ninths. 1 ninth = 5:50 minutes (leap year = 5:51 mins).
29 # section #2, labeled seconds
31 # block characters, ▉, are added every 3 seconds, a total of 20 for 1
32 # minute. The groups of 5 blocks = 15 seconds each.
34 # section #3, labeled mins
36 # Only enabled by clicking on seconds, see usage.
38 # Block characters are added every minute until 30, then reset. There
39 # are 6 groups of 5 minutes.
43 # Half hours in orange, grouped into groups of 2. This will grow until
44 # it fills the screen.
48 # Only enabled by clicking on mins section, see usage.
50 # These repeat sections 3 and 4 in violet and some other color.
53 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
55 source /a
/bin
/errhandle
/err
66 if date -d 'february 29' &>/dev
/null
; then
74 if [[ /b
/data
/daystart
-ot /b
/data
/daystart-generated
&& $day_start_24h ]]; then
77 day_start_24h
=$
(cat /b
/data
/daystart
)
78 day_start_sig_digits
=${day_start_24h%?}
79 day_start_sig_digits
=${day_start_sig_digits%0}
80 day_start_hour
=${day_start_24h%??}
81 day_start_min
=${day_start_24h: -2}
82 echo $day_start_hour > /b
/data
/daystart-generated
83 echo $day_start_min >> /b
/data
/daystart-generated
84 day_start
=$
(date -d $day_start_hour:$day_start_min +%s
)
85 # for after midnight but before the day start.
86 if (( day_start
> EPOCHSECONDS
)); then
87 day_start
=$
(date -d "$day_start_hour:$day_start_min yesterday" +%s
)
96 # if [[ $line ]]; then
97 # echo "line=$line" >>/tmp/t
103 case $
(echo "$json" | jq
-r .name
) in
105 case $
(echo "$json" | jq
-r .button
) in
118 case $
(echo "$json" | jq
-r .button
) in
131 time=$
((EPOCHSECONDS
- start
))
132 total_mins
=$
(( time / 60 ))
133 mins
=$
(( total_mins
% 30 ))
134 half_hours
=$
(( total_mins
/ 30 ))
141 if [[ $start2 ]]; then
142 time2
=$
((EPOCHSECONDS
- start2
))
143 total_mins2
=$
(( time2
/ 60 ))
144 mins2
=$
(( total_mins2
% 30 ))
145 half_hours2
=$
(( total_mins2
/ 30 ))
146 # this is duplicate of mins and half hours except for different
147 # colors and looking at vars above.
150 printf '{ "color": "#EFC93E", "full_text": "'
151 for ((i
=half_hours2-1
; i
>= 0 ; i--
)); do
153 if (( i
> 0 && i
% 2 == 0 )); then
161 printf '{ "name":"mins2", "color":"#ED297D", "full_text": "'
162 for ((i
=29; i
>= 0 ; i--
)); do
163 if (( i
< mins2
)); then
168 if (( i
> 0 && i
% 5 == 0 )); then
178 printf '{ "color": "#FFB542", "full_text": "'
179 for ((i
=half_hours-1
; i
>= 0 ; i--
)); do
181 if (( i
> 0 && i
% 2 == 0 )); then
189 printf '{ "name":"mins", "color":"#0D6BDD", "full_text": "'
190 for ((i
=29; i
>= 0 ; i--
)); do
191 if (( i
< mins
)); then
196 if (( i
> 0 && i
% 5 == 0 )); then
204 printf '{ "name": "seconds", "full_text": "'
206 for ((i
=0; i
< 20; i
++)); do
207 # This first condition is to make the transition from full to empty
208 # be less jarring. We are filling a bucket of space with ticks of
209 # time, we would have to choose to show full or empty, but never
210 # both. Or we could have a half/tick to show full then empty real
211 # quick. I decided to try having it work like a snake, empty out the
212 # 1st quarter as we fill up the last quarter.
214 if (( i
> 0 && i
% 5 == 0 )); then
217 i_end
=$
(( time % 60 / 3 + 1 ))
218 if (( i_end
- i
> 15 )); then
220 elif (( i_end
== 1 && i
== 0 )); then
222 elif (( i
< i_end
)); then
230 ## begin day percent, in thousandths, plus a spark block for ten_thousandth.
231 printf '{ "name": "day_percent", "full_text": "'
234 # after 24 hours, reset the day start
235 if (( day_start
+ 24 * 60 * 60 < EPOCHSECONDS
)); then
236 day_start
=$
(date -d $day_start_hour:$day_start_min +%s
)
239 # there are 9 spark levels, 1/9 = .111.... In order to keep it in bash math, we upscale
240 # the number and divide by 111, 3 digits is good enough accuracy.
241 spark_index
="$(( (1000000 -($EPOCHSECONDS - $day_start)*1000000 / (16*60*60) ) % 1000 / 111 ))"
243 # note: 960 minutes, so 10 minutes is about 1%
244 day_thousandth
=$
(( 1000 - (EPOCHSECONDS
- day_start
)*1000 / (16*60*60) ))
245 printf %s
"$day_thousandth${spark:spark_index:1}$day_start_sig_digits $(date "+%l
:%M
")"
247 # .1% of a waking year is ~5.75 hours, or 365 thousandths of a day.
248 # 1% of a waking year is 3.7 days
249 # A spark line of a thousandth of a waking year is 39 minutes.
250 year_start
=$
(date +%s
-d 'january 1 6am')
251 year_days
=$
(( (EPOCHSECONDS
- year_start
) / (24*60*60) ))
252 year_start
=$
(( year_start
+ year_days
* 8*60*60 ))
253 year_spark_index
=$
(( ( 1000000 - (EPOCHSECONDS
- year_start
)*1000000 / (days_in_this_year
*16*60*60) ) % 1000 / 111 ))
254 year_tenthousandth
=$
(( 10000 - (EPOCHSECONDS
- year_start
)*10000 / (days_in_this_year
*16*60*60) ))
255 printf %s
" $year_tenthousandth${spark:year_spark_index:1}"
264 # pass any arg and we just run once. mainly for debugging
269 #echo date -d $day_start_hour:$day_start_min +%s
270 #echo day_start=$day_start now=$EPOCHSECONDS
273 printf '{ "version": 1, "click_events": true }\n['
277 read -r -t 3 line ||
: