diff options
author | Philip Wittamore <philip@wittamore.com> | 2025-06-28 00:36:47 +0200 |
---|---|---|
committer | Philip Wittamore <philip@wittamore.com> | 2025-06-28 00:36:47 +0200 |
commit | 4790f80cfc5bd977b336f4a3e112ae9faeafb6bc (patch) | |
tree | 249530d9edbfb12bf9e5085685ee0cd1dfe0344b /pw-battery | |
parent | 28dd2120a2551af6b901d37e66d23359298ec603 (diff) | |
download | scripts-4790f80cfc5bd977b336f4a3e112ae9faeafb6bc.tar.gz scripts-4790f80cfc5bd977b336f4a3e112ae9faeafb6bc.tar.bz2 scripts-4790f80cfc5bd977b336f4a3e112ae9faeafb6bc.zip |
update
Diffstat (limited to 'pw-battery')
-rwxr-xr-x | pw-battery | 108 |
1 files changed, 59 insertions, 49 deletions
@@ -7,52 +7,62 @@ # kill -36 $(pidof dwmblocks) or # pkill -RTMIN+2 dwmblocks -# Loop through all attached batteries. -for battery in /sys/class/power_supply/BAT?*; do - # If non-first battery, print a space separator. - [ -n "${capacity+x}" ] && printf " " - - capacity="$(cat "$battery/capacity" 2>&1)" - if [ "$capacity" -gt 90 ]; then - status="✅ " - elif [ "$capacity" -gt 60 ]; then - status="🔋 " - elif [ "$capacity" -gt 40 ]; then - status="🪫 " - elif [ "$capacity" -gt 10 ]; then - status="⚠️ " - else - status="❌ " - fi - - case "$(cat "$battery/status" 2>&1)" in - - "Full") - status="⚡🔋" - ;; - - "Discharging") - if [ "$capacity" -le 20 ]; then - status="$status" - fi - ;; - - "Charging") - status="🔌$status" - ;; - - "Not charging") - status="♻" - ;; - - "Unknown") - status="? $status" - ;; - - *) - exit 1 - ;; - esac - - echo -e " $status $capacity% ┊" -done +bat="BAT0" + +battery="/sys/class/power_supply/$bat" + +capacity="$(cat "$battery/capacity" 2>&1)" +if [ "$capacity" -gt 95 ]; then + status="" +elif [ "$capacity" -gt 90 ]; then + status="" +elif [ "$capacity" -gt 80 ]; then + status="" +elif [ "$capacity" -gt 70 ]; then + status="" +elif [ "$capacity" -gt 60 ]; then + status="" +elif [ "$capacity" -gt 50 ]; then + status="" +elif [ "$capacity" -gt 40 ]; then + status="" +elif [ "$capacity" -gt 30 ]; then + status="" +elif [ "$capacity" -gt 20 ]; then + status="" +elif [ "$capacity" -gt 10 ]; then + status="" +else + status="" +fi + +case "$(cat "$battery/status" 2>&1)" in +"Full") + status="⚡$status" + ;; + +"Discharging") + #[ "$rrtn" -eq "$rrtn" ] && remaining="$(date -u -d @$((rrtn * 60)) +'%-Hh%-Mm')" + rrtn="$(cat /sys/devices/platform/smapi/$bat/remaining_running_time_now)" + [ "$rrtn" -eq "$rrtn" ] && remaining="$((rrtn/60))h$((rrtn%60))" + status="$remaining $status" + ;; + +"Charging") + status=" $status" + ;; + +"Not charging") + status=" status" + ;; + +"Unknown") + status="? $status" + ;; + +*) + exit 1 + ;; +esac + +echo -e " $status $capacity% \uE0b1" |