7183a8ff7eec6360277ed807bfad2befc7925ca4
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
/bash-bear-trap
/bash-bear
68 if date -d 'february 29' &>/dev
/null
; then
76 if [[ /b
/data
/daystart
-ot /b
/data
/daystart-generated
&& $day_start_24h ]]; then
79 day_start_24h
=$
(cat /b
/data
/daystart
)
80 day_start_sig_digits
=${day_start_24h%?}
81 day_start_sig_digits
=${day_start_sig_digits%0}
82 day_start_hour
=${day_start_24h%??}
83 day_start_min
=${day_start_24h: -2}
84 echo $day_start_hour > /b
/data
/daystart-generated
85 echo $day_start_min >> /b
/data
/daystart-generated
86 day_start
=$
(date -d $day_start_hour:$day_start_min +%s
)
87 # for after midnight but before the day start.
88 if (( day_start
> EPOCHSECONDS
)); then
89 day_start
=$
(date -d "$day_start_hour:$day_start_min yesterday" +%s
)
98 # if [[ $line ]]; then
99 # echo "line=$line" >>/tmp/t
105 case $
(echo "$json" | jq
-r .name
) in
107 case $
(echo "$json" | jq
-r .button
) in
120 case $
(echo "$json" | jq
-r .button
) in
133 time=$
((EPOCHSECONDS
- start
))
134 total_mins
=$
(( time / 60 ))
135 mins
=$
(( total_mins
% 30 ))
136 half_hours
=$
(( total_mins
/ 30 ))
142 if [[ -e /dev
/shm
/iank-status
&& ! -e /tmp
/quiet-status
]]; then
144 eval "$(< /dev/shm/iank-status)"
147 touch --date="10 minutes ago" $tmp_focus1
148 touch --date="30 minutes ago" $tmp_focus2
149 f
=/tmp
/focus-last-input
151 # We output a reminder to do input to the focus app if we haven't done
152 # it less 10 minutes ago (but dont bother if its been more than 30
153 # minutes, maybe we aren't running it anymore.)
154 if [[ -e $f && $tmp_focus2 -ot $f && $tmp_focus1 -nt $f ]]; then
155 ps_char
="=======FOCUS====== $ps_char"
159 printf '{ "name":"status", "color":"#ED297D", "full_text": "%s' "$ps_char"
163 if [[ $start2 ]]; then
164 time2
=$
((EPOCHSECONDS
- start2
))
165 total_mins2
=$
(( time2
/ 60 ))
166 mins2
=$
(( total_mins2
% 30 ))
167 half_hours2
=$
(( total_mins2
/ 30 ))
168 # this is duplicate of mins and half hours except for different
169 # colors and looking at vars above.
172 printf '{ "color": "#EFC93E", "full_text": "'
173 for ((i
=half_hours2-1
; i
>= 0 ; i--
)); do
175 if (( i
> 0 && i
% 2 == 0 )); then
183 printf '{ "name":"mins2", "color":"#ED297D", "full_text": "'
184 for ((i
=29; i
>= 0 ; i--
)); do
185 if (( i
< mins2
)); then
190 if (( i
> 0 && i
% 5 == 0 )); then
200 printf '{ "color": "#FFB542", "full_text": "'
201 for ((i
=half_hours-1
; i
>= 0 ; i--
)); do
203 if (( i
> 0 && i
% 2 == 0 )); then
211 printf '{ "name":"mins", "color":"#0D6BDD", "full_text": "'
212 for ((i
=29; i
>= 0 ; i--
)); do
213 if (( i
< mins
)); then
218 if (( i
> 0 && i
% 5 == 0 )); then
226 printf '{ "name": "seconds", "full_text": "'
228 for ((i
=0; i
< 20; i
++)); do
229 # This first condition is to make the transition from full to empty
230 # be less jarring. We are filling a bucket of space with ticks of
231 # time, we would have to choose to show full or empty, but never
232 # both. Or we could have a half/tick to show full then empty real
233 # quick. I decided to try having it work like a snake, empty out the
234 # 1st quarter as we fill up the last quarter.
236 if (( i
> 0 && i
% 5 == 0 )); then
239 i_end
=$
(( time % 60 / 3 + 1 ))
240 if (( i_end
- i
> 15 )); then
242 elif (( i_end
== 1 && i
== 0 )); then
244 elif (( i
< i_end
)); then
252 ## begin day percent, in thousandths, plus a spark block for ten_thousandth.
253 printf '{ "name": "day_percent", "full_text": "'
256 # after 24 hours, reset the day start
257 if (( day_start
+ 24 * 60 * 60 < EPOCHSECONDS
)); then
258 day_start
=$
(date -d $day_start_hour:$day_start_min +%s
)
261 # there are 9 spark levels, 1/9 = .111.... In order to keep it in bash math, we upscale
262 # the number and divide by 111, 3 digits is good enough accuracy.
263 spark_index
="$(( (1000000 -(EPOCHSECONDS - day_start)*1000000 / (16*60*60) ) % 1000 / 111 ))"
265 # note: 960 minutes, so 10 minutes is about 1%
266 day_thousandth
=$
(( 1000 - (EPOCHSECONDS
- day_start
)*1000 / (16*60*60) ))
267 printf %s
"$day_thousandth${spark:spark_index:1}$day_start_sig_digits $(date "+%l
:%M
")"
269 # .1% of a waking year is ~5.75 hours, or 365 thousandths of a day.
270 # 1% of a waking year is 3.7 days
271 # A spark line of a thousandth of a waking year is 39 minutes.
272 year_start
=$
(date +%s
-d 'january 1 6am')
273 year_days
=$
(( (EPOCHSECONDS
- year_start
) / (24*60*60) ))
274 year_start
=$
(( year_start
+ year_days
* 8*60*60 ))
275 year_spark_index
=$
(( ( 1000000 - (EPOCHSECONDS
- year_start
)*1000000 / (days_in_this_year
*16*60*60) ) % 1000 / 111 ))
276 year_tenthousandth
=$
(( 10000 - (EPOCHSECONDS
- year_start
)*10000 / (days_in_this_year
*16*60*60) ))
277 printf %s
" $year_tenthousandth${spark:year_spark_index:1}"
286 # pass any arg and we just run once. mainly for debugging
291 #echo date -d $day_start_hour:$day_start_min +%s
292 #echo day_start=$day_start now=$EPOCHSECONDS
295 printf '{ "version": 1, "click_events": true }\n['
297 if [[ -e /tmp
/noi3bar
]]; then
302 read -r -t 3 line ||
:
307 rm -f $tmp_focus1 $tmp_focus2