Created
October 6, 2018 15:54
-
-
Save hhromic/a82ef92a586f6581a8926f87163f96c6 to your computer and use it in GitHub Desktop.
Show the current capacity of all managed batteries in Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Show the current capacity of all managed batteries | |
# script by github.com/hhromic | |
POWER_SUPPLY_DIR=/sys/class/power_supply | |
mapfile -t CAPACITIES < <(compgen -G "$POWER_SUPPLY_DIR"/'*'/capacity) | |
for capacity in "${CAPACITIES[@]}"; do | |
battery="${capacity%/*}" | |
battery="${battery##*/}" | |
printf "%s=%s"$'\n' "$battery" "$(cat "$capacity")" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment