testsAndMisc/linux_configuration/dwm/bin/dwmstatus
Krzysztof kuhy Rudnicki 038e08d2be feat: split oversized modules for 500-line limit, fix kasa coverage gap
Split diet_guard/_gatelock.py, wake_alarm/_alarm.py, and the
usage_report.py/_usage_report_parsing.py pair into focused
sub-modules so every Python file is <= 500 lines, satisfying
test_file_length.py. Install python-kasa into .venv (declared in
requirements but missing after the 3.13->3.14 venv upgrade),
fixing 8 failing smart_plug tests and restoring 100% coverage.

Also includes prior in-progress work from the working tree: the
wake_alarm Progress/View/Hardware field-grouping refactor,
brother_printer query module + tests, diet_guard foodbank/state/cli
updates, new shared coerce/logging_setup helpers, morning_routine
orchestrator tweaks, dwm window-manager config, gaming scripts, and
misc maintenance/digital-wellbeing script updates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 07:19:37 +02:00

80 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# dwm status feeder — sets the root window name, which dwm paints in the bar.
# Run `dwmstatus once` to print the line a single time (no xsetroot required).
set -u
# Echo the primary temperature (temp1_input, whole °C) of the first hwmon chip
# whose name matches the given ERE. Echoes nothing if no such chip/sensor exists.
read_temp() {
local want=$1 d n milli
for d in /sys/class/hwmon/hwmon*/; do
[[ -r ${d}name ]] || continue
read -r n < "${d}name"
[[ $n =~ $want ]] || continue
[[ -r ${d}temp1_input ]] || return 0
read -r milli < "${d}temp1_input"
printf '%d' "$((milli / 1000))"
return 0
done
}
# Format kibibytes as a compact GiB/MiB string (e.g. 11.2GiB).
fmt_kib() {
local mib=$(( $1 / 1024 ))
if ((mib >= 1024)); then
printf '%d.%dGiB' "$((mib / 1024))" "$((((mib % 1024) * 10) / 1024))"
else
printf '%dMiB' "$mib"
fi
}
# Assemble the whole status line into $_status.
build_status() {
local cpu gpu mb load total avail raw mute vol now temps=""
cpu=$(read_temp 'k10temp|coretemp')
gpu=$(read_temp 'amdgpu|nouveau|radeon')
mb=$(read_temp 'nct[0-9]|it87|f71')
[[ -n $cpu ]] && temps+="CPU ${cpu}C "
[[ -n $gpu ]] && temps+="GPU ${gpu}C "
[[ -n $mb ]] && temps+="MB ${mb}C "
read -r load _ < /proc/loadavg
total=0 avail=0
while IFS=' :' read -r key value _; do
case $key in
MemTotal) total=$value ;;
MemAvailable) avail=$value ;;
esac
done < /proc/meminfo
vol="?"
raw=$(pactl get-sink-volume @DEFAULT_SINK@ 2>/dev/null) || raw=""
[[ $raw =~ ([0-9]+)% ]] && vol="${BASH_REMATCH[1]}%"
mute=$(pactl get-sink-mute @DEFAULT_SINK@ 2>/dev/null) || mute=""
[[ $mute == *yes ]] && vol="mute"
printf -v now '%(%Y-%m-%d %H:%M)T' -1
_status=" ${temps}RAM $(fmt_kib "$((total - avail))")/$(fmt_kib "$total") load ${load} vol ${vol} ${now} "
}
if [[ ${1:-} == once ]]; then
build_status
printf '%s\n' "$_status"
exit 0
fi
# Need xsetroot to actually paint the bar; without it the bar just stays empty.
if ! command -v xsetroot >/dev/null 2>&1; then
printf 'dwmstatus: xorg-xsetroot not installed; run: sudo pacman -S xorg-xsetroot\n' >&2
exit 0
fi
while :; do
build_status
xsetroot -name "$_status"
sleep 5
done