#!/bin/bash
-# Copyright (C) 2019 Ian Kelling
-# SPDX-License-Identifier: AGPL-3.0-or-later
+# I, Ian Kelling, follow the GNU license recommendations at
+# https://www.gnu.org/licenses/license-recommendations.en.html. They
+# recommend that small programs, < 300 lines, be licensed under the
+# Apache License 2.0. This file contains or is part of one or more small
+# programs. If a small program grows beyond 300 lines, I plan to switch
+# its license to GPL.
+
+# Copyright 2024 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
# usage:
-# * left click seconds to reset main timer
+#
+# * left click seconds to reset & enable main timer which shows 30
+# minutes in blue and half hours in orange.
+#
# * right click seconds to disable minutes & half hours of main timer
-# * left click minutes to reset 2nd timer.
+#
+# * left click minutes to reset & enable 2nd timer.
+#
# * right click minutes to disable 2nd timer
+# docs:
+#
+# Sections from right to left.
+#
+# section #1, labeled day_percent
+#
+# 1. Thousandths of a 16 hour day left. 1 = 57.6 seconds.
+# 2. Bar of one thousand of a day which gets shorter by ninths. One ninth is 6.4 seconds.
+# 3. Start of the day (only the non-zero numbers). Set this with the ds command.
+# 4. The time right now.
+# 5. Ten thousands of the year left. 1 = 52:34 minutes (leap year = 52:42)
+# 6. Bar of 1/10,000 of a year shrinking by ninths. 1 ninth = 5:50 minutes (leap year = 5:51 mins).
+#
+# section #2, labeled seconds
+#
+# block characters, ▉, are added every 3 seconds, a total of 20 for 1
+# minute. The groups of 5 blocks = 15 seconds each.
+#
+# section #3, labeled mins
+#
+# Only enabled by clicking on seconds, see usage.
+#
+# Block characters are added every minute until 30, then reset. There
+# are 6 groups of 5 minutes.
+#
+# Section #4
+#
+# Half hours in orange, grouped into groups of 2. This will grow until
+# it fills the screen.
+#
+# Section #5 & 6
+#
+# Only enabled by clicking on mins section, see usage.
+#
+# These repeat sections 3 and 4 in violet and some other color.
+#
+#
if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
-source /a/bin/errhandle/err
+source /a/bin/bash-bear-trap/bash-bear
shopt -s nullglob
shopt -s dotglob
+tmp_focus1=$(mktemp)
+tmp_focus2=$(mktemp)
+
mins=0
half_hours=0
-fast_blocks=30
start=$EPOCHSECONDS
-domins=true
+domins=false
+if date -d 'february 29' &>/dev/null; then
+ days_in_this_year=366
+else
+ days_in_this_year=365
+fi
get_daystart() {
- if [[ /b/data/daystart -ot /b/data/daystart-generated && $day_tmp ]]; then
+ if [[ /b/data/daystart -ot /b/data/daystart-generated && $day_start_24h ]]; then
return 0
fi
- day_tmp=$(cat /b/data/daystart)
- day_start_hour=${day_tmp%??}
- day_start_min=${day_tmp: -2}
+ day_start_24h=$(cat /b/data/daystart)
+ day_start_sig_digits=${day_start_24h%?}
+ day_start_sig_digits=${day_start_sig_digits%0}
+ day_start_hour=${day_start_24h%??}
+ day_start_min=${day_start_24h: -2}
echo $day_start_hour > /b/data/daystart-generated
echo $day_start_min >> /b/data/daystart-generated
day_start=$(date -d $day_start_hour:$day_start_min +%s)
case $(echo "$json" | jq -r .name) in
seconds)
case $(echo "$json" | jq -r .button) in
+ # left click
1)
start=$EPOCHSECONDS
domins=true
;;
+ # right click
3)
domins=false
;;
printf '['
+ if [[ -e /dev/shm/iank-status && ! -e /tmp/quiet-status ]]; then
+ ps_char=
+ eval "$(< /dev/shm/iank-status)"
+ fi
+
+ touch --date="10 minutes ago" $tmp_focus1
+ touch --date="30 minutes ago" $tmp_focus2
+ f=/tmp/focus-last-input
+
+ # We output a reminder to do input to the focus app if we haven't done
+ # it less 10 minutes ago (but dont bother if its been more than 30
+ # minutes, maybe we aren't running it anymore.)
+ if [[ -e $f && $tmp_focus2 -ot $f && $tmp_focus1 -nt $f ]]; then
+ ps_char="=======FOCUS====== $ps_char"
+ fi
+
+ if [[ -e /tmp/iank-i3-no-auto ]]; then
+ ps_char="$ps_char I"
+ fi
+
+ # not using currently
+ # if [[ -e /tmp/no-obs-auto-scene-switch ]]; then
+ # ps_char="$ps_char O"
+ # fi
+
+ if pgrep -fc '^ffmpeg.*icecast://source.*/fsf' &>/dev/null; then
+ if [[ -e /tmp/iank-ffmpeg-interlude-toggle ]]; then
+ ps_char="= BRB = $ps_char"
+ else
+ ps_char="=|=|= STREAMING =|=|= $ps_char"
+ fi
+
+ muted=$(cat $HOME/.iank-stream-muted) ||:
+ case $muted in
+ 0) : ;;
+ 1)
+ if find $HOME/.iank-stream-muted -mmin +2 | grep . &>/dev/null && \
+ ! pgrep -fc '^ffmpeg.*icecast://source.*/fsf-test'; then
+ toggle-mute mute notify
+ else
+ ps_char="# UNMUTED # $ps_char"
+ fi
+ ;;
+ *)
+ ps_char="!!!!! FAILED GETTING MUTE STATUS !!!!! $ps_char"
+ ;;
+ esac
+ fi
+
+ # fyi: to check system mute:
+ # if pactl get-source-mute @DEFAULT_SOURCE@ 2>/dev/null | awk '{print $2}' | grep no &>/dev/null; then
+
+
+
+ printf '{ "name":"status", "color":"#ED297D", "full_text": "%s' "$ps_char"
+ printf '"},'
+
if [[ $start2 ]]; then
time2=$((EPOCHSECONDS - start2))
i_end=$(( time % 60 / 3 + 1 ))
if (( i_end - i > 15 )); then
printf " "
+ elif (( i_end == 1 && i == 0 )); then
+ printf B
elif (( i < i_end )); then
printf ▉
else
day_start=$(date -d $day_start_hour:$day_start_min +%s)
fi
- spark_index="$(( (100000 -($EPOCHSECONDS - $day_start)*100000 / (16*60*60) ) % 100 / 11 ))"
+ # there are 9 spark levels, 1/9 = .111.... In order to keep it in bash math, we upscale
+ # the number and divide by 111, 3 digits is good enough accuracy.
+ spark_index="$(( (1000000 -(EPOCHSECONDS - day_start)*1000000 / (16*60*60) ) % 1000 / 111 ))"
spark=" ▁▂▃▄▅▆▇█"
# note: 960 minutes, so 10 minutes is about 1%
day_thousandth=$(( 1000 - (EPOCHSECONDS - day_start)*1000 / (16*60*60) ))
- printf %s "$day_thousandth${spark:spark_index:1} $(date "+%l:%M")"
+ printf %s "$day_thousandth${spark:spark_index:1}$day_start_sig_digits $(date "+%l:%M")"
# .1% of a waking year is ~5.75 hours, or 365 thousandths of a day.
# 1% of a waking year is 3.7 days
year_start=$(date +%s -d 'january 1 6am')
year_days=$(( (EPOCHSECONDS - year_start) / (24*60*60) ))
year_start=$(( year_start + year_days * 8*60*60 ))
- year_spark_index=$(( ( 100000 - (EPOCHSECONDS - year_start)*100000 / (365*16*60*60) ) % 100 / 11 ))
- year_tenthousandth=$(( 10000 - (EPOCHSECONDS - year_start)*10000 / (365*16*60*60) ))
+ year_spark_index=$(( ( 1000000 - (EPOCHSECONDS - year_start)*1000000 / (days_in_this_year*16*60*60) ) % 1000 / 111 ))
+ year_tenthousandth=$(( 10000 - (EPOCHSECONDS - year_start)*10000 / (days_in_this_year*16*60*60) ))
printf %s " $year_tenthousandth${spark:year_spark_index:1}"
else
printf '{ "version": 1, "click_events": true }\n['
while true; do
- main
- line=
- read -r -t 3 line ||:
+ if [[ -e /tmp/noi3bar ]]; then
+ sleep 10
+ else
+ main
+ line=
+ read -r -t 3 line ||:
+ fi
done
fi
+
+rm -f $tmp_focus1 $tmp_focus2