From df0ea6a174df3d930b162e28250d7617e63b37ba Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Fri, 16 Jul 2021 18:56:20 +0200 Subject: [PATCH] tidied up battery --- .local/bin/statusbar/battery | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.local/bin/statusbar/battery b/.local/bin/statusbar/battery index 8279ae2..2ca8219 100755 --- a/.local/bin/statusbar/battery +++ b/.local/bin/statusbar/battery @@ -17,12 +17,24 @@ for battery in /sys/class/power_supply/BAT? do # Get its remaining capacity and charge status. capacity=$(cat "$battery"/capacity 2>/dev/null) - [ -n "$capacity" ] && [ "$capacity" -gt 100 ] && echo "Error. Capacity:$capacity" > /dev/stderr && continue #do not print misreads - [ -z "$capacity" ] && echo "Error. Capacity:$capacity" > /dev/stderr && continue #if battery fails during reading, quit - [ -n "$capacity" ] && [ "$capacity" -eq 100 ] && echo && continue # do not display full batteries (nice to unclutter status bars for laptops mostly used stationiary) - status=$(sed "s/Discharging/🔋/;s/Not charging/🛑/;s/Charging/🔌/;s/Unknown/🔋/;s/Full/⚡/" "$battery"/status) - # If it is discharging and 25% or less, we will add a ❗ as a warning. - [ "$capacity" -le 25 ] && [ "$status" = "🔋" ] && warn="❗" - printf "%s%s%s%%\n" "$status" "$warn" "$capacity" - unset warn + if [ -n "$capacity" ]; then + #do not print misreads + [ "$capacity" -gt 100 ] && + echo "Error. Capacity:$capacity" > /dev/stderr && + continue + # do not display full batteries (nice to unclutter status bars for laptops mostly used stationiary) + [ "$capacity" -eq 100 ] && + printf '\n' && + continue + + status=$(sed "s/Discharging/🔋/;s/Not charging/🛑/;s/Charging/🔌/;s/Unknown/🔋/;s/Full/⚡/" "$battery"/status) + # If it is discharging and 25% or less, we will add a ❗ as a warning. + [ "$capacity" -le 25 ] && + [ "$status" = "🔋" ] && + warn="❗" + printf "%s%s%s%%\n" "$status" "$warn" "$capacity" + unset warn + else + echo "Error. Capacity:$capacity" > /dev/stderr #if battery fails during reading, quit + fi done | sed 's/ *$//'