Skip to content

Instantly share code, notes, and snippets.

@hhromic
Created October 6, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhromic/a82ef92a586f6581a8926f87163f96c6 to your computer and use it in GitHub Desktop.
Save hhromic/a82ef92a586f6581a8926f87163f96c6 to your computer and use it in GitHub Desktop.
Show the current capacity of all managed batteries in Linux
#!/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