mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 19:27:03 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
56 lines
1.7 KiB
Bash
Executable File
56 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# Automation tutor status for i3blocks: today's credited 15-minute blocks.
|
|
#
|
|
# A click runs plc-lab's run.sh, which starts the tutor if it is down and
|
|
# opens it in the browser -- nobody has to remember the port. Hidden once all
|
|
# four blocks are in: nothing left to earn, nothing to click.
|
|
#
|
|
# Counts the tutor ledger's credit rows dated today. It does not check their
|
|
# HMAC (that needs the key and Python); earned_time does, so this is a
|
|
# display, never the authority on what was paid.
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
readonly LEDGER="${AUTOMATION_TUTOR_LEDGER:-$HOME/.local/share/automation_tutor/ledger.json}"
|
|
# i3blocks' PATH has no ~/src: absolute path.
|
|
readonly RUN="${AUTOMATION_TUTOR_RUN:-$HOME/src/plc-lab/run.sh}"
|
|
readonly TARGET=4
|
|
|
|
readonly YELLOW='#F1FA8C'
|
|
readonly ORANGE='#FFB86C'
|
|
|
|
emit() {
|
|
# full_text, short_text, color — the three lines i3blocks reads.
|
|
printf '%s\n%s\n%s\n' "$1" "$2" "$3"
|
|
}
|
|
|
|
if [[ ${BLOCK_BUTTON:-0} -ne 0 ]]; then
|
|
setsid -f "$RUN" >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
emit '⚙ tutor: no jq' '⚙ ?' "$ORANGE"
|
|
exit 0
|
|
fi
|
|
|
|
printf -v today '%(%Y-%m-%d)T' -1
|
|
done_blocks=0
|
|
# No ledger yet is a real zero: the tutor creates it on the first block.
|
|
if [[ -e $LEDGER ]]; then
|
|
if ! done_blocks=$(jq --arg d "$today" \
|
|
'[.entries[] | select(.kind == "credit" and .day == $d)] | length' \
|
|
"$LEDGER" 2>/dev/null); then
|
|
emit '⚙ tutor: ledger unreadable' '⚙ ?' "$ORANGE"
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
if ((done_blocks >= TARGET)); then
|
|
emit '' '' "$YELLOW"
|
|
exit 0
|
|
fi
|
|
emit "⚙ tutor ${done_blocks}/${TARGET}" "⚙ ${done_blocks}/${TARGET}" "$YELLOW"
|