testsAndMisc/linux_configuration/i3-configuration/i3blocks/activitywatch_status.sh
Krzysztof kuhy Rudnicki 11c792ef3a fix(linux_configuration): harden polling/runtime scripts and add tests
- music_parallelism.sh + thesis_work_tracker.sh: tighter state-output and
  error paths; expanded regression tests.
- hosts-file-monitor.sh + shutdown-timer-monitor.sh: harden against partial
  failures, matching new test branches.
- i3blocks persist_common.sh helper improved (consumed by activitywatch /
  warp status blocks).
- setup_midnight_shutdown.sh + thesis_work_status.sh: state parsing tuned.
- pacman_blocked_keywords.txt: drop one obsolete entry.
- New test_thesis_work_status.sh regression script.

All six bash regression tests pass.
2026-05-14 19:55:42 +02:00

74 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# ActivityWatch status script for i3blocks.
set -euo pipefail
SCRIPT_DIR=${BASH_SOURCE[0]%/*}
[[ $SCRIPT_DIR == "${BASH_SOURCE[0]}" ]] && SCRIPT_DIR='.'
# shellcheck source=linux_configuration/i3-configuration/i3blocks/persist_common.sh
source "$SCRIPT_DIR/persist_common.sh"
check_installed() {
command -v aw-qt > /dev/null 2>&1 || command -v aw-server > /dev/null 2>&1
}
check_running() {
local proc_file proc_name
for proc_file in /proc/[0-9]*/comm; do
[[ -r $proc_file ]] || continue
read -r proc_name < "$proc_file" || continue
case $proc_name in
aw-qt | aw-server)
return 0
;;
esac
done
return 1
}
emit() {
local state
if ! check_installed; then
state='uninstalled'
elif check_running; then
state='on'
else
state='off'
fi
if ! i3blocks_update_if_changed_key "activitywatch_state" "$state"; then
return 0
fi
if [[ $state == 'uninstalled' ]]; then
echo "AW uninstalled"
echo
echo "#FF0000"
elif [[ $state == 'on' ]]; then
echo "AW on"
echo
echo "#00FF00"
else
echo "AW off"
echo
echo "#FF0000"
fi
}
is_persist_mode() {
[[ ${BLOCK_INTERVAL:-} == "persist" ]]
}
HEARTBEAT_INTERVAL_S=60
emit
if is_persist_mode; then
# Intentionally calm heartbeat in persist mode: process-table event streams can
# be extremely noisy and cause unnecessary churn.
while true; do
i3blocks_wait_seconds "$HEARTBEAT_INTERVAL_S"
emit
done
fi