Skip to content

Instantly share code, notes, and snippets.

@abenson
Last active March 20, 2023 21:01
Show Gist options
  • Save abenson/63c88d3ee5a4f0699307cc17d1416cb0 to your computer and use it in GitHub Desktop.
Save abenson/63c88d3ee5a4f0699307cc17d1416cb0 to your computer and use it in GitHub Desktop.
#!/bin/sh
for bat in /sys/class/power_supply/BAT?/uevent; do
_state=$(grep -w POWER_SUPPLY_NAME "$bat" | cut -d= -f2)
_charge=$(grep -w POWER_SUPPLY_CHARGE_NOW "$bat" | cut -d= -f2)
_full=$(grep -w POWER_SUPPLY_CHARGE_FULL "$bat" | cut -d= -f2)
_design=$(grep -w POWER_SUPPLY_CHARGE_FULL_DESIGN "$bat" | cut -d= -f2)
printf "$POWER_SUPPLY_NAME Status: %s\n" "${_state}"
printf "$POWER_SUPPLY_NAME Charge: %d%%\n" $(( (_charge * 100) / _full ))
printf "$POWER_SUPPLY_NAME Health: %d%%\n" $(( (_full * 100) / _design ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment