mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-19 07:54:22 +01:00
i3blocks: add Claude usage block, fix icon rendering, drop dead blocks
Add a [claude_usage] block showing the 5h and 7d rate-limit windows. It
reads ~/.claude/cache/limit-state/*.json, which Claude Code's statusLine
hook already writes to disk, so the data costs nothing to display: the
script only runs jq against a local file and makes no API call. Limits
are account-wide while the cache is sharded one file per project, so it
takes the newest file and ignores cwd. Percentages arrive as floats and
are truncated; a stale cache is labelled rather than shown as current,
and a rolled-over window reads "?%" instead of a misleading value.
Replace Font Awesome private-use-area icons with plain Unicode. Both
fonts named in the bar's pango string ("System San Francisco Display",
"FontAwesome") are not installed, so PUA codepoints fell through to
whatever font claimed them: ethernet rendered as a star, wifi as
Cyrillic, gpu as Hangul, disk as a chess pawn. Emoji resolve through
fontconfig consistently, which the pre-existing volume block already
relied on, and need no change to ~/.config/i3/config.
Remove the bluetooth, battery, wifi, activitywatch, warp and
network_monitor blocks: this desktop has no BT adapter, no battery, no
wireless interface, and no warp-cli. This also removes a rendering bug,
since activitywatch_status.sh and warp_status.sh were interval=persist
yet emitted three lines per update, leaking their colour line into the
bar as literal "#FF0000" text.
Fix ethernet reporting "down" on a live wired link:
find_ethernet_interface returned the first non-loopback interface, which
with docker installed is a br-* bridge (permanently down, and sorted
before enp*). It now requires a real /sys/class/net/*/device and prefers
an interface that is up.
Tests drop the assertions and fixtures for the removed blocks and add
claude_usage coverage (fresh, warn, critical, stale, rolled-over, null
reset, unparsable, missing dir), a guard that removed blocks cannot
return, a repo-wide check that no block script uses a PUA codepoint, and
an ethernet physical-NIC regression check. The fork budget is asserted
against a populated cache directory, which caught a stat call inside the
scan loop that cost one fork per cached project (170 -> 2 execs).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQLwdquDCNmWtvgi3Lk72J
This commit is contained in:
parent
5d0caa9725
commit
58c1df573c
@ -0,0 +1,21 @@
|
||||
{
|
||||
"title": "i3 bar: add Claude usage block, fix broken icons, remove dead blocks",
|
||||
"objective": "Surface Claude Code's 5-hour and 7-day rate-limit windows in the i3 status bar, replace Font Awesome private-use-area icon codepoints that render as wrong glyphs (the fonts named in the bar's pango string are not installed), and remove status blocks for hardware/software absent from this desktop.",
|
||||
"acceptance_criteria": [
|
||||
"A [claude_usage] block renders '5h NN% · 7d NN%' matching the newest ~/.claude/cache/limit-state/*.json",
|
||||
"claude_usage degrades safely: stale cache is labelled, a rolled-over window reads '?%' instead of a misleading number, and missing/unparsable data reads 'no data'",
|
||||
"No script under i3blocks/ contains a private-use-area codepoint (U+E000-U+F8FF) or a \\uEXXX/\\uFXXX escape",
|
||||
"No literal colour string (e.g. #FF0000) is rendered as visible text in the bar",
|
||||
"The bluetooth, battery, wifi, activitywatch, warp and network_monitor blocks are absent from the config and their scripts deleted",
|
||||
"The ethernet block reports the physical NIC's address rather than a docker bridge's permanent 'down'",
|
||||
"bash linux_configuration/tests/test_i3blocks_efficiency.sh exits 0",
|
||||
"pre-commit passes on all changed files"
|
||||
],
|
||||
"out_of_scope": [
|
||||
"Editing ~/.config/i3/config or its font line (it has drifted from the repo by three live-only exec lines; the emoji approach avoids needing a font change)",
|
||||
"Installing a Nerd Font or any new font package",
|
||||
"Restarting i3 while a fullscreen game session is running",
|
||||
"Any change to blocks that already render correctly (volume, shutdown_countdown, pc_startup)"
|
||||
],
|
||||
"verifier": "bash linux_configuration/tests/test_i3blocks_efficiency.sh; pre-commit run --files <changed>; i3blocks -c ~/.config/i3blocks/config -o i3bar (inspect emitted JSON)"
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
{
|
||||
"intent": "Show Claude Code's 5h/7d rate-limit usage in the i3 bar, make the status icons render as the symbols they are meant to be, and stop displaying blocks for hardware this desktop does not have.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/periodic_background/i3-configuration/i3blocks/ (config + block scripts)",
|
||||
"linux_configuration/tests/test_i3blocks_efficiency.sh",
|
||||
"Non-goal: ~/.config/i3/config and its font line are deliberately untouched (drifted from repo by three live-only exec lines)",
|
||||
"Non-goal: installing fonts"
|
||||
],
|
||||
"changes": [
|
||||
"Added claude_usage.sh: interval=60, 3-line i3blocks protocol, reads the newest ~/.claude/cache/limit-state/*.json (limits are account-wide but the cache is sharded per-cwd, so newest-by-mtime wins and cwd is ignored). Truncates float percentages, tolerates a null seven_day_resets_at, labels stale data, and reports '?%' for a rolled-over window instead of a misleading cached value.",
|
||||
"Replaced Font Awesome private-use-area codepoints with plain Unicode emoji in cpu_monitor, gpu_monitor, motherboard_temp, memory, disk, ethernet and time. Root cause: both fonts named in the bar's pango string ('System San Francisco Display', 'FontAwesome') are not installed, so PUA codepoints fell through to arbitrary fonts - ethernet rendered as a star, wifi as Cyrillic, gpu as Hangul, disk as a chess pawn.",
|
||||
"Removed the bluetooth, battery, wifi, activitywatch, warp and network_monitor blocks and their scripts, plus the dangling ~/.config/i3blocks symlinks they left behind. This also removed a rendering bug: activitywatch_status.sh and warp_status.sh were interval=persist yet emitted three lines per update, so their trailing colour line was displayed as literal '#FF0000' text in the bar.",
|
||||
"Fixed a pre-existing ethernet bug: find_ethernet_interface returned the first non-loopback interface, which on a machine with docker installed is a br-* bridge (permanently 'down' and alphabetically before enp*), so the bar showed 'down' on a live wired link. It now requires a real /sys/class/net/*/device and prefers an interface that is actually up.",
|
||||
"Updated test_i3blocks_efficiency.sh: dropped assertions and fixtures for the removed blocks, added claude_usage behaviour/fork-budget tests (fresh, warn, critical, stale, rolled-over, null reset, unparsable, missing dir), a guard that removed blocks do not return, a repo-wide check that no block script contains a PUA codepoint, and an ethernet physical-NIC regression check."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash linux_configuration/tests/test_i3blocks_efficiency.sh",
|
||||
"result": "pass",
|
||||
"evidence": "EXIT=0; 'All i3blocks efficiency regression tests passed.' Includes the new 'Checking Claude usage block behavior and fork count' and 'Checking status icons avoid Font Awesome private-use codepoints' sections."
|
||||
},
|
||||
{
|
||||
"command": "i3blocks -c ~/.config/i3blocks/config -o i3bar",
|
||||
"result": "pass",
|
||||
"evidence": "Emitted blocks: cpu 🖥 57°C | gpu 🎮 70°C | mobo 🌡 58°C | memory 🧠 13.8GiB/30.4GiB | disk 💾 1.3T/3.6T | volume 🔊 100% | ethernet 🌐 192.168.1.43/24 | claude_usage 🤖 5h 38% · 7d 55% | pc_startup PC:warn | shutdown ⏻ 23:00 | time 🕑 2026-08-10 15:07. No PUA glyphs, no literal colour text, no removed blocks."
|
||||
},
|
||||
{
|
||||
"command": "./claude_usage.sh vs jq -s 'max_by(.updated_at)' ~/.claude/cache/limit-state/*.json",
|
||||
"result": "pass",
|
||||
"evidence": "Script printed '🤖 5h 36% · 7d 55%' while the cache reported five_hour_pct=36, seven_day_pct=55.00000000000001. Edge cases exercised with a synthetic LIMIT_STATE_DIR: stale -> '(stale)' grey, rolled window -> '5h ?%', null seven_day reset -> normal render, corrupt/missing/empty -> '🤖 no data'."
|
||||
},
|
||||
{
|
||||
"command": "pre-commit run --files <changed-files>",
|
||||
"result": "pass",
|
||||
"evidence": "shellcheck, codespell, polling-antipattern, binary-file and secret-leak hooks all pass after fixing SC2016 and a codespell hit."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"Emoji are rendered by Segoe UI Emoji via fontconfig fallback; if that font were removed the icons would degrade to tofu. Mitigated by the fact that the pre-existing 🔊 and ⏻ blocks already depended on the same path and render correctly.",
|
||||
"claude_usage only refreshes while a Claude Code session is open, because the underlying cache is written by the statusLine hook. Handled explicitly by the stale label rather than silently showing an old number.",
|
||||
"Config-stanza changes need i3blocks to be respawned (i3blocks has no config-reload signal). Script edits are live immediately via the symlinks."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit; the deleted block scripts return with it.",
|
||||
"Recreate the ~/.config/i3blocks symlinks for any restored scripts (ln -sf into the repo i3blocks dir) and remove the claude_usage.sh symlink.",
|
||||
"Run i3-msg restart, then confirm the bar renders and bash linux_configuration/tests/test_i3blocks_efficiency.sh exits 0."
|
||||
]
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
#!/bin/bash
|
||||
# ActivityWatch status script for i3blocks.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR=${BASH_SOURCE[0]%/*}
|
||||
[[ $SCRIPT_DIR == "${BASH_SOURCE[0]}" ]] && SCRIPT_DIR='.'
|
||||
# shellcheck source=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
|
||||
@ -1,62 +0,0 @@
|
||||
#!/bin/bash
|
||||
# i3blocks battery indicator, zero-fork per invocation.
|
||||
#
|
||||
# Reads /sys/class/power_supply directly instead of forking `acpi | awk`.
|
||||
# Uses only bash builtins (read, printf, arithmetic, parameter expansion).
|
||||
|
||||
set -u
|
||||
|
||||
# Nerd Font glyph: battery-full icon (U+F240).
|
||||
ICON=$'\uf240'
|
||||
|
||||
bat=
|
||||
for d in /sys/class/power_supply/BAT*/; do
|
||||
[[ -d $d ]] && {
|
||||
bat=$d
|
||||
break
|
||||
}
|
||||
done
|
||||
|
||||
if [[ -z $bat ]]; then
|
||||
# Desktop with no battery — emit empty block so i3bar hides it.
|
||||
echo
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cap='N/A'
|
||||
[[ -r ${bat}capacity ]] && read -r cap < "${bat}capacity"
|
||||
|
||||
status=''
|
||||
[[ -r ${bat}status ]] && read -r status < "${bat}status"
|
||||
|
||||
# Compute time remaining from energy_now/power_now (µWh / µW → hours).
|
||||
# Falls back to charge_now/current_now on batteries that expose charge instead.
|
||||
time_str=''
|
||||
num=0
|
||||
den=0
|
||||
if [[ -r ${bat}energy_now && -r ${bat}power_now ]]; then
|
||||
read -r num < "${bat}energy_now"
|
||||
read -r den < "${bat}power_now"
|
||||
elif [[ -r ${bat}charge_now && -r ${bat}current_now ]]; then
|
||||
read -r num < "${bat}charge_now"
|
||||
read -r den < "${bat}current_now"
|
||||
fi
|
||||
if ((den > 0 && num > 0)); then
|
||||
total_min=$((num * 60 / den))
|
||||
printf -v time_str '%02d:%02d' "$((total_min / 60))" "$((total_min % 60))"
|
||||
fi
|
||||
|
||||
color='#50FA7B'
|
||||
if [[ $cap =~ ^[0-9]+$ ]]; then
|
||||
if ((cap < 15)); then
|
||||
color='#FF5555'
|
||||
elif ((cap < 35)); then
|
||||
color='#F1FA8C'
|
||||
fi
|
||||
fi
|
||||
[[ $status == Charging ]] && color='#8BE9FD'
|
||||
|
||||
printf -v body '%s %s%%' "$ICON" "$cap"
|
||||
[[ -n $time_str ]] && body+=", $time_str"
|
||||
[[ $status == Charging ]] && body+=', '
|
||||
printf '<span color="%s">%s</span>\n' "$color" "$body"
|
||||
@ -1,72 +0,0 @@
|
||||
#!/bin/bash
|
||||
# i3blocks bluetooth indicator.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR=${BASH_SOURCE[0]%/*}
|
||||
[[ $SCRIPT_DIR == "${BASH_SOURCE[0]}" ]] && SCRIPT_DIR='.'
|
||||
# shellcheck source=persist_common.sh
|
||||
source "$SCRIPT_DIR/persist_common.sh"
|
||||
|
||||
get_bluetooth_info() {
|
||||
local info
|
||||
info=$(bluetoothctl info 2>/dev/null) || info=''
|
||||
printf '%s\n' "$info"
|
||||
}
|
||||
|
||||
emit() {
|
||||
local bluetooth_info connected device line state_key
|
||||
bluetooth_info=$(get_bluetooth_info)
|
||||
|
||||
connected='no'
|
||||
device=''
|
||||
while IFS= read -r line; do
|
||||
case $line in
|
||||
*'Connected: yes')
|
||||
connected='yes'
|
||||
;;
|
||||
*'Alias: '*)
|
||||
device=${line#*Alias: }
|
||||
;;
|
||||
esac
|
||||
done <<<"$bluetooth_info"
|
||||
|
||||
state_key="$connected|$device"
|
||||
if ! i3blocks_update_if_changed_key "bluetooth_state" "$state_key"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ $connected == yes && -n $device ]]; then
|
||||
echo " $device"
|
||||
echo
|
||||
echo "#50FA7B"
|
||||
else
|
||||
echo " Disconnected"
|
||||
fi
|
||||
}
|
||||
|
||||
is_persist_mode() {
|
||||
[[ ${BLOCK_INTERVAL:-} == "persist" ]]
|
||||
}
|
||||
|
||||
emit_throttled() {
|
||||
if ! i3blocks_should_emit_by_interval_key "bluetooth_emit" "$EMIT_MIN_INTERVAL_S"; then
|
||||
return 0
|
||||
fi
|
||||
emit
|
||||
}
|
||||
|
||||
EMIT_MIN_INTERVAL_S=2
|
||||
|
||||
emit
|
||||
|
||||
if is_persist_mode; then
|
||||
# React to BlueZ D-Bus signals instead of polling.
|
||||
if command -v dbus-monitor >/dev/null 2>&1; then
|
||||
dbus-monitor --system "type='signal',sender='org.bluez'" 2>/dev/null |
|
||||
while read -r line; do
|
||||
[[ $line == *"PropertiesChanged"* ]] || continue
|
||||
emit_throttled
|
||||
done
|
||||
fi
|
||||
fi
|
||||
@ -0,0 +1,127 @@
|
||||
#!/bin/bash
|
||||
# Claude Code rate-limit status script for i3blocks.
|
||||
# Shows the 5-hour and 7-day usage windows as percentages.
|
||||
#
|
||||
# Data source: ~/.claude/cache/limit-state/*.json, written by the Claude Code
|
||||
# statusLine hook (~/.claude/scripts/statusline.sh) roughly every 60s while a
|
||||
# session is open. The cache is sharded one file per project cwd, but the
|
||||
# limits themselves are ACCOUNT-WIDE - so we read only the most recently
|
||||
# updated file and ignore its "cwd" field entirely. That keeps this to a
|
||||
# single file read per tick instead of scanning ~170 files.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
LIMIT_STATE_DIR=${LIMIT_STATE_DIR:-$HOME/.claude/cache/limit-state}
|
||||
|
||||
# Beyond this age the cached numbers no longer reflect reality, because the
|
||||
# writer only runs while a Claude session is open. We surface that rather than
|
||||
# presenting a stale number as current.
|
||||
STALE_AFTER_S=${STALE_AFTER_S:-900}
|
||||
|
||||
ICON='🤖'
|
||||
|
||||
readonly COLOR_OK='#50FA7B'
|
||||
readonly COLOR_WARN='#F1FA8C'
|
||||
readonly COLOR_CRIT='#FF5555'
|
||||
readonly COLOR_UNKNOWN='#6272A4'
|
||||
|
||||
# i3blocks 3-line protocol: full_text, short_text, color.
|
||||
emit() {
|
||||
printf '%s\n%s\n%s\n' "$1" "$2" "$3"
|
||||
exit 0
|
||||
}
|
||||
|
||||
get_now_epoch() {
|
||||
if [[ -n ${NOW_EPOCH:-} ]]; then
|
||||
printf '%s\n' "$NOW_EPOCH"
|
||||
else
|
||||
printf '%(%s)T\n' -1
|
||||
fi
|
||||
}
|
||||
|
||||
# Newest cache file by mtime. A glob + builtin comparison keeps this fork-free;
|
||||
# `ls -t | head -1` would spend two processes to answer the same question.
|
||||
newest_state_file() {
|
||||
local candidate newest=''
|
||||
for candidate in "$LIMIT_STATE_DIR"/*.json; do
|
||||
[[ -f $candidate ]] || continue
|
||||
# `-nt` is a bash builtin mtime comparison: it keeps this loop fork-free
|
||||
# even though the directory holds one file per project (~170 of them).
|
||||
# Calling `stat` here instead would cost a fork per file, every tick.
|
||||
if [[ -z $newest ]] || [[ $candidate -nt $newest ]]; then
|
||||
newest=$candidate
|
||||
fi
|
||||
done
|
||||
[[ -n $newest ]] || return 1
|
||||
printf '%s\n' "$newest"
|
||||
}
|
||||
|
||||
now_epoch=$(get_now_epoch)
|
||||
|
||||
if ! state_file=$(newest_state_file); then
|
||||
emit "$ICON no data" "$ICON --" "$COLOR_UNKNOWN"
|
||||
fi
|
||||
|
||||
# One jq invocation extracts every field. Percentages are floats in the source
|
||||
# (e.g. 55.00000000000001), so floor them here; `resets_at` may be null.
|
||||
if ! fields=$(jq -r '
|
||||
[ (.five_hour_pct // "null"),
|
||||
(.five_hour_resets_at // "null"),
|
||||
(.seven_day_pct // "null"),
|
||||
(.seven_day_resets_at // "null"),
|
||||
(.updated_at // "null") ]
|
||||
| map(if . == "null" then "null" else (. | floor | tostring) end)
|
||||
| @tsv' -- "$state_file" 2>/dev/null); then
|
||||
emit "$ICON no data" "$ICON --" "$COLOR_UNKNOWN"
|
||||
fi
|
||||
|
||||
IFS=$'\t' read -r five_pct five_resets seven_pct seven_resets updated_at <<<"$fields"
|
||||
|
||||
# A window whose reset time has passed has rolled over; the cached percentage
|
||||
# for it is meaningless, so report unknown rather than a misleading 0%.
|
||||
window_text() {
|
||||
local label=$1 pct=$2 resets=$3
|
||||
if [[ $pct == 'null' ]]; then
|
||||
printf '%s ?%%' "$label"
|
||||
return
|
||||
fi
|
||||
if [[ $resets != 'null' ]] && [[ $resets -lt $now_epoch ]]; then
|
||||
printf '%s ?%%' "$label"
|
||||
return
|
||||
fi
|
||||
printf '%s %s%%' "$label" "$pct"
|
||||
}
|
||||
|
||||
# Colour tracks the window closest to its limit, but only for windows whose
|
||||
# value is still trustworthy (not rolled over).
|
||||
worst_pct=-1
|
||||
consider_pct() {
|
||||
local pct=$1 resets=$2
|
||||
[[ $pct == 'null' ]] && return 0
|
||||
[[ $resets != 'null' ]] && [[ $resets -lt $now_epoch ]] && return 0
|
||||
[[ $pct -gt $worst_pct ]] && worst_pct=$pct
|
||||
return 0
|
||||
}
|
||||
|
||||
consider_pct "$five_pct" "$five_resets"
|
||||
consider_pct "$seven_pct" "$seven_resets"
|
||||
|
||||
full_text="$ICON $(window_text '5h' "$five_pct" "$five_resets") · $(window_text '7d' "$seven_pct" "$seven_resets")"
|
||||
short_text="$ICON $(window_text '5h' "$five_pct" "$five_resets")"
|
||||
|
||||
# Stale data outranks the usage colouring: the numbers may be arbitrarily old.
|
||||
if [[ $updated_at == 'null' ]] || [[ $((now_epoch - updated_at)) -gt $STALE_AFTER_S ]]; then
|
||||
emit "$full_text (stale)" "$short_text" "$COLOR_UNKNOWN"
|
||||
fi
|
||||
|
||||
if [[ $worst_pct -lt 0 ]]; then
|
||||
color=$COLOR_UNKNOWN
|
||||
elif [[ $worst_pct -ge 85 ]]; then
|
||||
color=$COLOR_CRIT
|
||||
elif [[ $worst_pct -ge 60 ]]; then
|
||||
color=$COLOR_WARN
|
||||
else
|
||||
color=$COLOR_OK
|
||||
fi
|
||||
|
||||
emit "$full_text" "$short_text" "$color"
|
||||
@ -28,54 +28,21 @@ interval=60
|
||||
color=#50FA7B
|
||||
|
||||
|
||||
|
||||
|
||||
[volume]
|
||||
command=~/.config/i3blocks/volume.sh
|
||||
interval=persist
|
||||
markup=pango
|
||||
|
||||
|
||||
|
||||
[bluetooth]
|
||||
command=~/.config/i3blocks/bluetooth.sh
|
||||
interval=persist
|
||||
color=#FFFFFF
|
||||
|
||||
|
||||
[battery]
|
||||
command=~/.config/i3blocks/battery_status.sh
|
||||
interval=60
|
||||
markup=pango
|
||||
|
||||
|
||||
[ethernet]
|
||||
command=~/.config/i3blocks/ethernet.sh
|
||||
interval=persist
|
||||
color=#FFFFFF
|
||||
|
||||
|
||||
[wifi]
|
||||
command=~/.config/i3blocks/wifi_monitor.sh
|
||||
interval=persist
|
||||
color=#FFFFFF
|
||||
|
||||
|
||||
#[network_monitor]
|
||||
#command=~/.config/i3blocks/network_monitor.sh
|
||||
#interval=1
|
||||
#color=#FFFFFF
|
||||
|
||||
|
||||
[warp]
|
||||
command=~/.config/i3blocks/warp_status.sh
|
||||
interval=persist
|
||||
|
||||
|
||||
[activitywatch]
|
||||
command=~/.config/i3blocks/activitywatch_status.sh
|
||||
interval=persist
|
||||
color=#FFFFFF
|
||||
[claude_usage]
|
||||
command=~/.config/i3blocks/claude_usage.sh
|
||||
interval=60
|
||||
|
||||
|
||||
[pc_startup]
|
||||
|
||||
@ -57,5 +57,7 @@ elif ((load_x100 > 0)); then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Nerd Font glyph: microchip / CPU icon (U+F2DB).
|
||||
printf '<span color="%s">\uf2db %s°C, %s</span>\n' "$color" "$temp" "$load"
|
||||
# CPU icon. Plain Unicode, not a Font Awesome PUA codepoint: the fonts named
|
||||
# in the i3 bar's pango string are not installed, so PUA glyphs fall through to
|
||||
# whatever random font claims them (this one used to render as a tiny box).
|
||||
printf '<span color="%s">🖥 %s°C, %s</span>\n' "$color" "$temp" "$load"
|
||||
|
||||
@ -7,8 +7,8 @@ set -euo pipefail
|
||||
read -r _
|
||||
read -r _ size used _
|
||||
} < <(df -h / 2> /dev/null) || {
|
||||
echo " N/A"
|
||||
echo "💾 N/A"
|
||||
exit 0
|
||||
}
|
||||
|
||||
echo " ${used}/${size}"
|
||||
echo "💾 ${used}/${size}"
|
||||
|
||||
@ -8,23 +8,37 @@ SCRIPT_DIR=${BASH_SOURCE[0]%/*}
|
||||
# shellcheck source=persist_common.sh
|
||||
source "$SCRIPT_DIR/persist_common.sh"
|
||||
|
||||
# Picks a real physical ethernet interface. Virtual interfaces (docker/podman
|
||||
# bridges, veth pairs, wireguard, tailscale, bonds) must be skipped: they sort
|
||||
# alphabetically BEFORE enp*/eth*, so taking the first match reported "down"
|
||||
# forever on a machine with docker installed, even with a live wired link.
|
||||
# Physical NICs are the ones with a real device symlink under /sys/class/net.
|
||||
find_ethernet_interface() {
|
||||
local iface_path iface
|
||||
local iface_path iface state fallback=''
|
||||
for iface_path in /sys/class/net/*; do
|
||||
iface=${iface_path##*/}
|
||||
[[ $iface == lo ]] && continue
|
||||
[[ -d ${iface_path}/wireless ]] && continue
|
||||
[[ -e ${iface_path}/device ]] || continue
|
||||
[[ -r ${iface_path}/operstate ]] || continue
|
||||
printf '%s\n' "$iface"
|
||||
return 0
|
||||
read -r state <"${iface_path}/operstate"
|
||||
# Prefer an interface that is actually up; remember the first physical
|
||||
# one so an all-down machine still reports a real NIC rather than none.
|
||||
if [[ $state == up ]]; then
|
||||
printf '%s\n' "$iface"
|
||||
return 0
|
||||
fi
|
||||
[[ -z $fallback ]] && fallback=$iface
|
||||
done
|
||||
return 1
|
||||
[[ -n $fallback ]] || return 1
|
||||
printf '%s\n' "$fallback"
|
||||
return 0
|
||||
}
|
||||
|
||||
emit() {
|
||||
local iface state addr_output output_line
|
||||
iface=$(find_ethernet_interface) || {
|
||||
output_line=' down'
|
||||
output_line='🌐 down'
|
||||
if i3blocks_update_if_changed_key "ethernet_output" "$output_line"; then
|
||||
printf '%s\n' "$output_line"
|
||||
fi
|
||||
@ -33,7 +47,7 @@ emit() {
|
||||
|
||||
read -r state <"/sys/class/net/${iface}/operstate"
|
||||
if [[ $state != up ]]; then
|
||||
output_line=' down'
|
||||
output_line='🌐 down'
|
||||
if i3blocks_update_if_changed_key "ethernet_output" "$output_line"; then
|
||||
printf '%s\n' "$output_line"
|
||||
fi
|
||||
@ -42,9 +56,9 @@ emit() {
|
||||
|
||||
addr_output=$(ip -o -4 addr show dev "$iface" scope global 2>/dev/null) || addr_output=''
|
||||
if [[ $addr_output =~ ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]+) ]]; then
|
||||
output_line=" ${BASH_REMATCH[1]}"
|
||||
output_line="🌐 ${BASH_REMATCH[1]}"
|
||||
else
|
||||
output_line=' down'
|
||||
output_line='🌐 down'
|
||||
fi
|
||||
|
||||
if i3blocks_update_if_changed_key "ethernet_output" "$output_line"; then
|
||||
|
||||
@ -18,7 +18,7 @@ SCRIPT_DIR=${BASH_SOURCE[0]%/*}
|
||||
source "$SCRIPT_DIR/persist_common.sh"
|
||||
|
||||
# Nerd Font glyph: display / desktop icon (U+F108).
|
||||
ICON=$'\uf108'
|
||||
ICON='🎮'
|
||||
|
||||
emit() {
|
||||
local temp=$1 load=$2 color
|
||||
@ -31,7 +31,7 @@ emit() {
|
||||
else
|
||||
color='#FF5555'
|
||||
fi
|
||||
printf '<span color="%s">%s %s°C, %s%%</span>\n' \
|
||||
printf '<span color="%s">%s %s°C, %s%%</span>\n' \
|
||||
"$color" "$ICON" "$temp" "$load"
|
||||
}
|
||||
|
||||
|
||||
@ -28,4 +28,4 @@ done < /proc/meminfo
|
||||
used_mib=$(((total_kib - available_kib) / 1024))
|
||||
total_mib=$((total_kib / 1024))
|
||||
|
||||
printf ' %s/%s\n' "$(format_mib "$used_mib")" "$(format_mib "$total_mib")"
|
||||
printf '🧠 %s/%s\n' "$(format_mib "$used_mib")" "$(format_mib "$total_mib")"
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
set -u
|
||||
|
||||
# Nerd Font glyph: thermometer icon (U+F2C9).
|
||||
ICON=$'\uf2c9'
|
||||
ICON='🌡'
|
||||
|
||||
hwmon=''
|
||||
for d in /sys/class/hwmon/hwmon*/; do
|
||||
@ -36,7 +36,7 @@ if [[ -z $hwmon ]]; then
|
||||
fi
|
||||
|
||||
if [[ -z $hwmon || ! -r ${hwmon}temp1_input ]]; then
|
||||
printf '<span color="#FF5555">%s MB: N/A</span>\n' "$ICON"
|
||||
printf '<span color="#FF5555">%s MB: N/A</span>\n' "$ICON"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@ -51,4 +51,4 @@ else
|
||||
color='#FF5555'
|
||||
fi
|
||||
|
||||
printf '<span color="%s">%s %s°C</span>\n' "$color" "$ICON" "$temp"
|
||||
printf '<span color="%s">%s %s°C</span>\n' "$color" "$ICON" "$temp"
|
||||
|
||||
@ -1,89 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to detect all active network interfaces
|
||||
detect_interfaces() {
|
||||
local iface_path iface state
|
||||
for iface_path in /sys/class/net/*; do
|
||||
iface=$(basename "$iface_path")
|
||||
if [[ $iface == "lo" || ! -d "/sys/class/net/$iface" ]]; then
|
||||
continue
|
||||
fi
|
||||
if [[ -r "/sys/class/net/$iface/operstate" ]]; then
|
||||
state=$(< "/sys/class/net/$iface/operstate")
|
||||
if [[ $state == "up" ]]; then
|
||||
printf '%s\n' "$iface"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Detect all active network interfaces
|
||||
mapfile -t interfaces < <(detect_interfaces)
|
||||
|
||||
# If no active interfaces are found, exit
|
||||
if [ "${#interfaces[@]}" -eq 0 ]; then
|
||||
echo "No active network interfaces found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Initialize total RX and TX bytes
|
||||
total_rx_now=0
|
||||
total_tx_now=0
|
||||
|
||||
# Initialize last recorded RX and TX bytes
|
||||
total_last_rx=0
|
||||
total_last_tx=0
|
||||
|
||||
# Initialize time variables without forking: read from /proc/uptime
|
||||
read -r uptime_s _ < /proc/uptime
|
||||
current_time=${uptime_s%%.*}
|
||||
last_time=$current_time
|
||||
|
||||
# Iterate over each interface and accumulate RX and TX bytes
|
||||
for interface in "${interfaces[@]}"; do
|
||||
rx_path="/sys/class/net/$interface/statistics/rx_bytes"
|
||||
tx_path="/sys/class/net/$interface/statistics/tx_bytes"
|
||||
|
||||
if ! read -r rx_now < "$rx_path"; then
|
||||
rx_now=0
|
||||
fi
|
||||
if ! read -r tx_now < "$tx_path"; then
|
||||
tx_now=0
|
||||
fi
|
||||
|
||||
state_file="/tmp/network_monitor_$interface"
|
||||
if [ -f "$state_file" ]; then
|
||||
read -r last_rx last_tx last_time < "$state_file"
|
||||
else
|
||||
last_rx=$rx_now
|
||||
last_tx=$tx_now
|
||||
fi
|
||||
|
||||
total_rx_now=$((total_rx_now + rx_now))
|
||||
total_tx_now=$((total_tx_now + tx_now))
|
||||
total_last_rx=$((total_last_rx + last_rx))
|
||||
total_last_tx=$((total_last_tx + last_tx))
|
||||
|
||||
# Save current RX and TX bytes for the next check (using uptime as source)
|
||||
printf '%s %s %s\n' "$rx_now" "$tx_now" "$current_time" > "$state_file"
|
||||
done
|
||||
|
||||
# Calculate time difference
|
||||
time_diff=$((current_time - last_time))
|
||||
|
||||
# Calculate total download and upload speeds in bytes per second
|
||||
if ((time_diff > 0)); then
|
||||
total_rx_rate=$(((total_rx_now - total_last_rx) / time_diff))
|
||||
total_tx_rate=$(((total_tx_now - total_last_tx) / time_diff))
|
||||
else
|
||||
total_rx_rate=0
|
||||
total_tx_rate=0
|
||||
fi
|
||||
|
||||
# Convert speeds to human-readable format
|
||||
rx_rate_human=$(numfmt --to=iec --suffix=B/s --padding=8 "$total_rx_rate")
|
||||
tx_rate_human=$(numfmt --to=iec --suffix=B/s --padding=8 "$total_tx_rate")
|
||||
|
||||
# Store the result of printf into a string and echo it
|
||||
printf " %s %s\n" "$rx_rate_human" "$tx_rate_human"
|
||||
echo "#50FA7B"
|
||||
@ -4,7 +4,7 @@
|
||||
set -uo pipefail
|
||||
|
||||
emit() {
|
||||
printf ' %(%Y-%m-%d %H:%M)T\n' -1
|
||||
printf '🕑 %(%Y-%m-%d %H:%M)T\n' -1
|
||||
}
|
||||
|
||||
while :; do
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
#!/bin/bash
|
||||
# i3blocks WARP indicator with a single helper process.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR=${BASH_SOURCE[0]%/*}
|
||||
[[ $SCRIPT_DIR == "${BASH_SOURCE[0]}" ]] && SCRIPT_DIR='.'
|
||||
# shellcheck source=persist_common.sh
|
||||
source "$SCRIPT_DIR/persist_common.sh"
|
||||
|
||||
if ! command -v warp-cli >/dev/null 2>&1; then
|
||||
echo " N/A"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
is_persist_mode() {
|
||||
[[ ${BLOCK_INTERVAL:-} == "persist" ]]
|
||||
}
|
||||
|
||||
WARP_POLL_INTERVAL_S=120
|
||||
|
||||
read_status() {
|
||||
local status line
|
||||
status=''
|
||||
while IFS= read -r line; do
|
||||
case $line in
|
||||
'Status update: '*)
|
||||
status=${line#Status update: }
|
||||
;;
|
||||
esac
|
||||
done < <(warp-cli status 2>/dev/null)
|
||||
printf '%s\n' "$status"
|
||||
}
|
||||
|
||||
emit_status() {
|
||||
local status=$1
|
||||
if [[ $status == Connected ]]; then
|
||||
echo "🔒 !!! WARP CONNECTED !!!"
|
||||
echo
|
||||
echo "#FFFF00"
|
||||
elif [[ $status == Disconnected ]]; then
|
||||
echo "WARP disconnected"
|
||||
echo
|
||||
echo "#00FF00"
|
||||
else
|
||||
echo "⚠️ ! WARP unknown !"
|
||||
echo
|
||||
echo "#FF0000"
|
||||
fi
|
||||
}
|
||||
|
||||
emit_if_changed() {
|
||||
local status=$1
|
||||
if ! i3blocks_update_if_changed_key "warp_status" "$status"; then
|
||||
return 0
|
||||
fi
|
||||
emit_status "$status"
|
||||
}
|
||||
|
||||
current_status=$(read_status)
|
||||
emit_status "$current_status"
|
||||
if is_persist_mode; then
|
||||
i3blocks_update_if_changed_key "warp_status" "$current_status" >/dev/null || true
|
||||
fi
|
||||
if is_persist_mode; then
|
||||
while true; do
|
||||
i3blocks_wait_seconds "$WARP_POLL_INTERVAL_S"
|
||||
current_status=$(read_status)
|
||||
emit_if_changed "$current_status"
|
||||
done
|
||||
fi
|
||||
@ -1,104 +0,0 @@
|
||||
#!/bin/bash
|
||||
# i3blocks Wi-Fi indicator with a small, bounded helper budget.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR=${BASH_SOURCE[0]%/*}
|
||||
[[ $SCRIPT_DIR == "${BASH_SOURCE[0]}" ]] && SCRIPT_DIR='.'
|
||||
# shellcheck source=persist_common.sh
|
||||
source "$SCRIPT_DIR/persist_common.sh"
|
||||
|
||||
find_wifi_interface() {
|
||||
local line
|
||||
while IFS= read -r line; do
|
||||
case $line in
|
||||
*'Interface '*)
|
||||
printf '%s\n' "${line##*Interface }"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
done < <(iw dev 2>/dev/null)
|
||||
return 1
|
||||
}
|
||||
|
||||
emit() {
|
||||
local wifi_interface ssid signal ip_address line fields i output_line
|
||||
|
||||
wifi_interface=$(find_wifi_interface) || {
|
||||
output_line=' down'
|
||||
if i3blocks_update_if_changed_key "wifi_output" "$output_line"; then
|
||||
echo "$output_line"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
ssid=''
|
||||
signal=''
|
||||
while IFS= read -r line; do
|
||||
case $line in
|
||||
'SSID: '*)
|
||||
ssid=${line#SSID: }
|
||||
;;
|
||||
'signal: '*)
|
||||
signal=${line#signal: }
|
||||
signal=${signal% dBm}
|
||||
;;
|
||||
'Not connected.'*)
|
||||
ssid=''
|
||||
;;
|
||||
esac
|
||||
done < <(iw dev "$wifi_interface" link 2>/dev/null)
|
||||
|
||||
if [[ -z $ssid ]]; then
|
||||
output_line=' down'
|
||||
if i3blocks_update_if_changed_key "wifi_output" "$output_line"; then
|
||||
echo "$output_line"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
ip_address=''
|
||||
while IFS= read -r line; do
|
||||
[[ $line == *' inet '* ]] || continue
|
||||
read -r -a fields <<<"$line"
|
||||
for ((i = 0; i < ${#fields[@]}; i++)); do
|
||||
if [[ ${fields[i]} == inet && $((i + 1)) -lt ${#fields[@]} ]]; then
|
||||
ip_address=${fields[i + 1]%%/*}
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done < <(ip -o -4 addr show dev "$wifi_interface" scope global 2>/dev/null)
|
||||
|
||||
if [[ -n $ip_address ]]; then
|
||||
output_line=" $ssid ($signal dBm) $ip_address"
|
||||
else
|
||||
output_line=" $ssid ($signal dBm)"
|
||||
fi
|
||||
|
||||
if i3blocks_update_if_changed_key "wifi_output" "$output_line"; then
|
||||
echo "$output_line"
|
||||
fi
|
||||
}
|
||||
|
||||
is_persist_mode() {
|
||||
[[ ${BLOCK_INTERVAL:-} == "persist" ]]
|
||||
}
|
||||
|
||||
emit_throttled() {
|
||||
if ! i3blocks_should_emit_by_interval_key "wifi_emit" "$EMIT_MIN_INTERVAL_S"; then
|
||||
return 0
|
||||
fi
|
||||
emit
|
||||
}
|
||||
|
||||
EMIT_MIN_INTERVAL_S=2
|
||||
|
||||
emit
|
||||
|
||||
if is_persist_mode; then
|
||||
ip monitor link address route 2>/dev/null |
|
||||
while read -r line; do
|
||||
[[ $line == *"wlan"* || $line == *"wl"* || $line == *"inet "* ]] || continue
|
||||
emit_throttled
|
||||
done
|
||||
fi
|
||||
@ -16,10 +16,6 @@ BIN_DIR="$TMP_DIR/bin"
|
||||
mkdir -p "$BIN_DIR"
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "${AW_PID:-}" ]]; then
|
||||
kill "$AW_PID" 2>/dev/null || true
|
||||
wait "$AW_PID" 2>/dev/null || true
|
||||
fi
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
@ -59,15 +55,6 @@ count_execs() {
|
||||
grep -c 'execve(' "$log_file"
|
||||
}
|
||||
|
||||
cat >"$BIN_DIR/bluetoothctl" <<'EOF'
|
||||
#!/bin/bash
|
||||
printf '%s\n' \
|
||||
'Device AA:BB:CC:DD:EE:FF' \
|
||||
'Alias: Test Headphones' \
|
||||
'Connected: yes'
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/bluetoothctl"
|
||||
|
||||
cat >"$BIN_DIR/pacman" <<'EOF'
|
||||
#!/bin/bash
|
||||
exit 1
|
||||
@ -124,20 +111,6 @@ exit 1
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/ip"
|
||||
|
||||
cat >"$BIN_DIR/warp-cli" <<'EOF'
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -eq 1 && $1 == status ]]; then
|
||||
printf 'Status update: %s\n' "${WARP_STATUS:-Disconnected}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf 'unexpected warp-cli args: %s\n' "$*" >&2
|
||||
exit 1
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/warp-cli"
|
||||
|
||||
cat >"$BIN_DIR/df" <<'EOF'
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
@ -154,8 +127,6 @@ exit 1
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/df"
|
||||
|
||||
ln -s /bin/sleep "$BIN_DIR/aw-qt"
|
||||
|
||||
printf 'Checking config uses dedicated low-fork scripts...\n'
|
||||
grep -q '^command=~/.config/i3blocks/time.sh$' "$CONFIG_FILE" \
|
||||
|| fail 'time block should call time.sh'
|
||||
@ -173,109 +144,128 @@ grep -A2 '^\[motherboard_temperature\]$' "$CONFIG_FILE" | grep -q '^interval=30$
|
||||
|| fail 'motherboard block should poll at 30s interval'
|
||||
grep -A2 '^\[memory\]$' "$CONFIG_FILE" | grep -q '^interval=30$' \
|
||||
|| fail 'memory block should poll at 30s interval'
|
||||
grep -A2 '^\[bluetooth\]$' "$CONFIG_FILE" | grep -q '^interval=persist$' \
|
||||
|| fail 'bluetooth block should use persist mode'
|
||||
grep -A2 '^\[battery\]$' "$CONFIG_FILE" | grep -q '^interval=60$' \
|
||||
|| fail 'battery block should poll at 60s interval'
|
||||
grep -A2 '^\[ethernet\]$' "$CONFIG_FILE" | grep -q '^interval=persist$' \
|
||||
|| fail 'ethernet block should use persist mode'
|
||||
grep -A2 '^\[wifi\]$' "$CONFIG_FILE" | grep -q '^interval=persist$' \
|
||||
|| fail 'wifi block should use persist mode'
|
||||
grep -A2 '^\[activitywatch\]$' "$CONFIG_FILE" | grep -q '^interval=persist$' \
|
||||
|| fail 'activitywatch block should use persist mode'
|
||||
grep -A2 '^\[warp\]$' "$CONFIG_FILE" | grep -q '^interval=persist$' \
|
||||
|| fail 'warp block should use persist mode'
|
||||
grep -A2 '^\[claude_usage\]$' "$CONFIG_FILE" | grep -q '^interval=60$' \
|
||||
|| fail 'claude_usage block should poll at 60s interval'
|
||||
grep -q '^command=~/.config/i3blocks/claude_usage.sh$' "$CONFIG_FILE" \
|
||||
|| fail 'claude_usage block should call claude_usage.sh'
|
||||
|
||||
# Blocks for hardware/software absent from this machine were removed; make sure
|
||||
# they do not silently return. Each rendered permanently-dead text in the bar.
|
||||
for removed_block in bluetooth battery wifi activitywatch warp network_monitor; do
|
||||
if grep -q "^\[${removed_block}\]$" "$CONFIG_FILE"; then
|
||||
fail "removed block [${removed_block}] should not be in the config"
|
||||
fi
|
||||
done
|
||||
|
||||
printf 'Checking status icons avoid Font Awesome private-use codepoints...\n'
|
||||
# The fonts named in the i3 bar's pango string are not installed, so private-use
|
||||
# codepoints (U+E000-U+F8FF) fall through to whatever font claims them - which
|
||||
# rendered the ethernet icon as a star and the wifi icon as Cyrillic. Plain
|
||||
# Unicode/emoji resolve consistently instead.
|
||||
for icon_script in "$I3BLOCKS_DIR"/*.sh; do
|
||||
if grep -qP '[\x{E000}-\x{F8FF}]|\\u[eEfF][0-9a-fA-F]{3}' "$icon_script"; then
|
||||
fail "$(basename "$icon_script") should not use private-use-area icon codepoints"
|
||||
fi
|
||||
done
|
||||
|
||||
printf 'Checking focus detection path avoids extra xdotool lookups...\n'
|
||||
! grep -Fq "xdotool getwindowname \"\$wid\"" "$REPO_DIR/scripts/lib/common.sh" \
|
||||
|| fail 'focus detection should not call xdotool getwindowname in hot path'
|
||||
|
||||
printf 'Checking ActivityWatch persist strategy avoids /proc event storm...\n'
|
||||
! grep -Fq 'inotifywait -m -q -e create -e delete /proc' "$I3BLOCKS_DIR/activitywatch_status.sh" \
|
||||
|| fail 'activitywatch persist mode should avoid noisy /proc inotify stream'
|
||||
|
||||
printf 'Checking GPU/WARP dedupe guards exist...\n'
|
||||
printf 'Checking GPU dedupe guards exist...\n'
|
||||
grep -Fq 'emit_if_changed()' "$I3BLOCKS_DIR/gpu_monitor.sh" \
|
||||
|| fail 'gpu monitor should dedupe repeated identical samples'
|
||||
grep -Fq 'emit_if_changed()' "$I3BLOCKS_DIR/warp_status.sh" \
|
||||
|| fail 'warp status should dedupe repeated identical states'
|
||||
grep -Fq "source \"\$SCRIPT_DIR/persist_common.sh\"" "$I3BLOCKS_DIR/bluetooth.sh" \
|
||||
|| fail 'bluetooth script should use shared persist helper'
|
||||
grep -Fq "source \"\$SCRIPT_DIR/persist_common.sh\"" "$I3BLOCKS_DIR/wifi_monitor.sh" \
|
||||
|| fail 'wifi script should use shared persist helper'
|
||||
grep -Fq "source \"\$SCRIPT_DIR/persist_common.sh\"" "$I3BLOCKS_DIR/ethernet.sh" \
|
||||
|| fail 'ethernet script should use shared persist helper'
|
||||
grep -Fq "source \"\$SCRIPT_DIR/persist_common.sh\"" "$I3BLOCKS_DIR/activitywatch_status.sh" \
|
||||
|| fail 'activitywatch script should use shared persist helper'
|
||||
grep -Fq "source \"\$SCRIPT_DIR/persist_common.sh\"" "$I3BLOCKS_DIR/gpu_monitor.sh" \
|
||||
|| fail 'gpu script should use shared persist helper'
|
||||
grep -Fq "source \"\$SCRIPT_DIR/persist_common.sh\"" "$I3BLOCKS_DIR/warp_status.sh" \
|
||||
|| fail 'warp script should use shared persist helper'
|
||||
grep -Fq 'i3blocks_update_if_changed_key "bluetooth_state"' "$I3BLOCKS_DIR/bluetooth.sh" \
|
||||
|| fail 'bluetooth script should dedupe unchanged state'
|
||||
grep -Fq 'i3blocks_update_if_changed_key "wifi_output"' "$I3BLOCKS_DIR/wifi_monitor.sh" \
|
||||
|| fail 'wifi script should dedupe unchanged output'
|
||||
grep -Fq 'i3blocks_update_if_changed_key "ethernet_output"' "$I3BLOCKS_DIR/ethernet.sh" \
|
||||
|| fail 'ethernet script should dedupe unchanged output'
|
||||
grep -Fq 'i3blocks_update_if_changed_key "activitywatch_state"' "$I3BLOCKS_DIR/activitywatch_status.sh" \
|
||||
|| fail 'activitywatch script should dedupe unchanged state'
|
||||
|
||||
printf 'Checking bluetooth block behavior and fork count...\n'
|
||||
bluetooth_output=$(PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/bluetooth.sh")
|
||||
assert_equals ' Test Headphones' "$(printf '%s\n' "$bluetooth_output" | sed -n '1p')" \
|
||||
'bluetooth script should show connected alias'
|
||||
assert_le "$(count_execs "$I3BLOCKS_DIR/bluetooth.sh")" 2 \
|
||||
'bluetooth script should stay at one external helper plus bash'
|
||||
printf 'Checking ethernet picks a physical NIC over virtual bridges...\n'
|
||||
# Regression: the old loop returned the first non-loopback interface, which on a
|
||||
# machine with docker installed is a `br-*` bridge (always "down", and sorted
|
||||
# before enp*/eth*), so the bar reported "down" on a live wired connection.
|
||||
grep -Fq 'iface_path}/device' "$I3BLOCKS_DIR/ethernet.sh" \
|
||||
|| fail 'ethernet script should require a real device to skip virtual interfaces'
|
||||
|
||||
printf 'Checking ActivityWatch block behavior and fork count...\n'
|
||||
activitywatch_output=$(PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/activitywatch_status.sh")
|
||||
assert_equals 'AW off' "$(printf '%s\n' "$activitywatch_output" | sed -n '1p')" \
|
||||
'activitywatch script should show AW off when not running'
|
||||
assert_le "$(count_execs "$I3BLOCKS_DIR/activitywatch_status.sh")" 1 \
|
||||
'activitywatch script should avoid pacman/pgrep hot-path forks'
|
||||
printf 'Checking Claude usage block behavior and fork count...\n'
|
||||
CLAUDE_STATE_DIR="$TMP_DIR/limit-state"
|
||||
mkdir -p "$CLAUDE_STATE_DIR"
|
||||
claude_now=1786366861
|
||||
|
||||
"$BIN_DIR/aw-qt" 60 >/dev/null 2>&1 &
|
||||
AW_PID=$!
|
||||
activitywatch_running_output=$(PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/activitywatch_status.sh")
|
||||
assert_equals 'AW on' "$(printf '%s\n' "$activitywatch_running_output" | sed -n '1p')" \
|
||||
'activitywatch script should detect running aw-qt process'
|
||||
write_claude_state() {
|
||||
printf '{"five_hour_pct":%s,"five_hour_resets_at":%s,"seven_day_pct":%s,"seven_day_resets_at":%s,"updated_at":%s}\n' \
|
||||
"$1" "$2" "$3" "$4" "$5" >"$CLAUDE_STATE_DIR/state.json"
|
||||
}
|
||||
|
||||
printf 'Checking Wi-Fi block behavior and fork count...\n'
|
||||
wifi_connected_output=$(PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/wifi_monitor.sh")
|
||||
assert_equals ' TestWifi (-53 dBm) 192.168.1.44' \
|
||||
"$wifi_connected_output" \
|
||||
'wifi script should show ssid, signal, and IP when connected'
|
||||
assert_le "$(count_execs "$I3BLOCKS_DIR/wifi_monitor.sh")" 4 \
|
||||
'wifi script should stay within bash plus iw/iw/ip exec budget'
|
||||
run_claude_usage() {
|
||||
LIMIT_STATE_DIR="$CLAUDE_STATE_DIR" NOW_EPOCH="$claude_now" \
|
||||
bash "$I3BLOCKS_DIR/claude_usage.sh"
|
||||
}
|
||||
|
||||
wifi_disconnected_output=$(WIFI_CONNECTED=0 PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/wifi_monitor.sh")
|
||||
assert_equals ' down' "$wifi_disconnected_output" \
|
||||
'wifi script should show down when the interface is not connected'
|
||||
# Percentages arrive as floats (e.g. 55.00000000000001) and must be truncated.
|
||||
write_claude_state 34 "$((claude_now + 3600))" 55.00000000000001 "$((claude_now + 99999))" "$claude_now"
|
||||
claude_output=$(run_claude_usage)
|
||||
assert_equals '🤖 5h 34% · 7d 55%' "$(printf '%s\n' "$claude_output" | sed -n '1p')" \
|
||||
'claude usage should show both windows as whole percentages'
|
||||
assert_equals '#50FA7B' "$(printf '%s\n' "$claude_output" | sed -n '3p')" \
|
||||
'claude usage should be green well below the limit'
|
||||
|
||||
wifi_missing_output=$(WIFI_HAS_INTERFACE=0 PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/wifi_monitor.sh") || true
|
||||
assert_equals ' down' "$wifi_missing_output" \
|
||||
'wifi script should show down when no Wi-Fi interface exists'
|
||||
write_claude_state 70 "$((claude_now + 3600))" 12 "$((claude_now + 99999))" "$claude_now"
|
||||
assert_equals '#F1FA8C' "$(run_claude_usage | sed -n '3p')" \
|
||||
'claude usage should warn when a window passes 60%'
|
||||
|
||||
printf 'Checking WARP block behavior and fork count...\n'
|
||||
warp_connected_output=$(WARP_STATUS=Connected PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/warp_status.sh")
|
||||
assert_equals '🔒 !!! WARP CONNECTED !!!' "$(printf '%s\n' "$warp_connected_output" | sed -n '1p')" \
|
||||
'warp script should show the connected warning when WARP is enabled'
|
||||
assert_equals '#FFFF00' "$(printf '%s\n' "$warp_connected_output" | sed -n '3p')" \
|
||||
'warp script should show yellow when WARP is connected'
|
||||
assert_le "$(count_execs "$I3BLOCKS_DIR/warp_status.sh")" 2 \
|
||||
'warp script should stay at one external helper plus bash'
|
||||
write_claude_state 91 "$((claude_now + 3600))" 12 "$((claude_now + 99999))" "$claude_now"
|
||||
assert_equals '#FF5555' "$(run_claude_usage | sed -n '3p')" \
|
||||
'claude usage should go critical when a window passes 85%'
|
||||
|
||||
warp_disconnected_output=$(WARP_STATUS=Disconnected PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/warp_status.sh")
|
||||
assert_equals 'WARP disconnected' "$(printf '%s\n' "$warp_disconnected_output" | sed -n '1p')" \
|
||||
'warp script should show the disconnected state'
|
||||
# The writer only runs while a Claude session is open, so old data must be
|
||||
# labelled rather than presented as the current figure.
|
||||
write_claude_state 34 "$((claude_now + 3600))" 55 "$((claude_now + 99999))" "$((claude_now - 5000))"
|
||||
assert_equals '🤖 5h 34% · 7d 55% (stale)' "$(run_claude_usage | sed -n '1p')" \
|
||||
'claude usage should mark stale cache data'
|
||||
|
||||
warp_unknown_output=$(WARP_STATUS=Unknown PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/warp_status.sh")
|
||||
assert_equals '⚠️ ! WARP unknown !' "$(printf '%s\n' "$warp_unknown_output" | sed -n '1p')" \
|
||||
'warp script should show the unknown state when status parsing fails'
|
||||
# A window whose reset time has passed has rolled over: its cached percentage is
|
||||
# meaningless, so it must read as unknown rather than a misleading value.
|
||||
write_claude_state 99 "$((claude_now - 10))" 55 "$((claude_now + 99999))" "$claude_now"
|
||||
assert_equals '🤖 5h ?% · 7d 55%' "$(run_claude_usage | sed -n '1p')" \
|
||||
'claude usage should not report a rolled-over window as current'
|
||||
|
||||
write_claude_state 34 "$((claude_now + 3600))" 55 null "$claude_now"
|
||||
assert_equals '🤖 5h 34% · 7d 55%' "$(run_claude_usage | sed -n '1p')" \
|
||||
'claude usage should tolerate a null seven_day reset time'
|
||||
|
||||
printf 'not json\n' >"$CLAUDE_STATE_DIR/state.json"
|
||||
assert_equals '🤖 no data' "$(run_claude_usage | sed -n '1p')" \
|
||||
'claude usage should degrade gracefully on unparsable cache data'
|
||||
|
||||
claude_missing_output=$(LIMIT_STATE_DIR="$TMP_DIR/no-such-dir" NOW_EPOCH="$claude_now" \
|
||||
bash "$I3BLOCKS_DIR/claude_usage.sh")
|
||||
assert_equals '🤖 no data' "$(printf '%s\n' "$claude_missing_output" | sed -n '1p')" \
|
||||
'claude usage should degrade gracefully when the cache directory is absent'
|
||||
|
||||
write_claude_state 34 "$((claude_now + 3600))" 55 "$((claude_now + 99999))" "$claude_now"
|
||||
assert_le "$(LIMIT_STATE_DIR="$CLAUDE_STATE_DIR" NOW_EPOCH="$claude_now" \
|
||||
count_execs "$I3BLOCKS_DIR/claude_usage.sh")" 3 \
|
||||
'claude usage should stay within bash plus jq'
|
||||
|
||||
# The real cache holds one file per project (~170 on this machine), so the
|
||||
# fork budget has to be measured against a populated directory. Measuring it
|
||||
# against a single-file dir hid a `stat` call sitting inside the scan loop.
|
||||
for filler in $(seq 1 200); do
|
||||
cp "$CLAUDE_STATE_DIR/state.json" "$CLAUDE_STATE_DIR/filler-$filler.json"
|
||||
done
|
||||
assert_le "$(LIMIT_STATE_DIR="$CLAUDE_STATE_DIR" NOW_EPOCH="$claude_now" \
|
||||
count_execs "$I3BLOCKS_DIR/claude_usage.sh")" 3 \
|
||||
'claude usage fork count must not scale with the number of cached projects'
|
||||
rm -f "$CLAUDE_STATE_DIR"/filler-*.json
|
||||
|
||||
printf 'Checking disk block behavior and fork count...\n'
|
||||
disk_output=$(PATH="$BIN_DIR:$PATH" bash "$I3BLOCKS_DIR/disk.sh")
|
||||
assert_equals ' 15G/100G' "$disk_output" \
|
||||
assert_equals '💾 15G/100G' "$disk_output" \
|
||||
'disk script should show used and total disk space'
|
||||
assert_le "$(count_execs "$I3BLOCKS_DIR/disk.sh")" 2 \
|
||||
'disk script should stay at one external helper plus bash'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user