diff options
author | ZachIR <zachir@librem.one> | 2025-08-09 08:36:53 -0500 |
---|---|---|
committer | ZachIR <zachir@librem.one> | 2025-08-09 08:39:05 -0500 |
commit | 2e178615cca5f59e12493b0540e753971c6dd22b (patch) | |
tree | 13d07b09022814b86dfdc2659ba607f4b3a487d9 /power_now | |
parent | 07d6429c676d7fc9771bc45ac85c100bd33656b5 (diff) |
Close power_now immediately if no battery
Diffstat (limited to 'power_now')
-rwxr-xr-x | power_now | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -12,10 +12,16 @@ while getopts "b:mqt" o; do case "${o}" in b) BATTERY="$OPTARG" ;; esac done +error () { + printf "%s\n" "$@" + exit 1 +} + #TOTALPOWER='0' case "$BATTERY" in "ALL") + ls -1 /sys/class/power_supply | grep -q 'BAT' || error "Are there no batteries?" for battery in $(ls -1 /sys/class/power_supply | grep 'BAT'); do DIRNAME="/sys/class/power_supply/${battery}" if [ -f "${DIRNAME}/power_now" ]; then @@ -59,7 +65,7 @@ case "$BATTERY" in ;; *) DIRNAME="/sys/class/power_supply/${BATTERY}" - [ -d "${DIRNAME}" ] || echo "No such battery!" + [ -d "${DIRNAME}" ] || error "No such battery!" if [ -f "${DIRNAME}/power_now" ]; then if [ -n "${MILLIWATTS}" ]; then POWER="$(cat "${DIRNAME}/power_now" | awk '{print $1/1e3}' | head -1)" |