60 lines
1.7 KiB
Bash
Executable File
60 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# One-shot hardware discovery for the Quickshell bar.
|
|
# Prints stable sysfs paths the QML side then reads directly via FileView,
|
|
# so no per-tick subprocess is needed. Output (one key per line):
|
|
#
|
|
# TEMP <path to hwmon/thermal temp*_input>
|
|
# BAT <path to power_supply battery dir>
|
|
#
|
|
# Re-run only when hardware topology might change (rare); paths are stable
|
|
# across a boot.
|
|
|
|
set -u
|
|
|
|
# CPU package temperature sensor (coretemp / k10temp / zenpower ...).
|
|
discover_temp_input() {
|
|
local hw name lbl base
|
|
for hw in /sys/class/hwmon/hwmon*; do
|
|
name=$(cat "$hw/name" 2>/dev/null) || continue
|
|
case "$name" in
|
|
coretemp|k10temp|zenpower)
|
|
# Prefer the package/Tctl/Tdie label if present.
|
|
for lbl in "$hw"/temp*_label; do
|
|
[ -e "$lbl" ] || continue
|
|
case "$(cat "$lbl" 2>/dev/null)" in
|
|
"Package id 0"|Tctl|Tdie)
|
|
base="${lbl%_label}"
|
|
echo "${base}_input"
|
|
return 0
|
|
;;
|
|
esac
|
|
done
|
|
[ -e "$hw/temp1_input" ] && { echo "$hw/temp1_input"; return 0; }
|
|
;;
|
|
esac
|
|
done
|
|
# Fallback: x86_pkg_temp thermal zone, else first thermal zone.
|
|
local z t
|
|
for z in /sys/class/thermal/thermal_zone*; do
|
|
t=$(cat "$z/type" 2>/dev/null)
|
|
[ "$t" = "x86_pkg_temp" ] && { echo "$z/temp"; return 0; }
|
|
done
|
|
[ -e /sys/class/thermal/thermal_zone0/temp ] && echo /sys/class/thermal/thermal_zone0/temp
|
|
}
|
|
|
|
# Main system battery (skip peripherals like wacom/mouse which set scope=Device).
|
|
discover_battery() {
|
|
local ps t scope
|
|
for ps in /sys/class/power_supply/*; do
|
|
t=$(cat "$ps/type" 2>/dev/null)
|
|
[ "$t" = "Battery" ] || continue
|
|
scope=$(cat "$ps/scope" 2>/dev/null)
|
|
[ "$scope" = "Device" ] && continue
|
|
echo "$ps"
|
|
return 0
|
|
done
|
|
}
|
|
|
|
printf 'TEMP %s\n' "$(discover_temp_input)"
|
|
printf 'BAT %s\n' "$(discover_battery)"
|