# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-BAT="BAT0"
-SYSPATH="/sys/class/power_supply/$BAT"
+for i in $(seq 0 9); do
+ BAT="BAT${i}"
+ SYSPATH="/sys/class/power_supply/$BAT"
+ if [ -d "${SYSPATH}" ]; then
+ break
+ fi
+done
+
+if [ ! -d "${SYSPATH}" ]; then
+ echo "No battery found in $(dirname "${SYSPATH}")"
+ exit 1
+fi
STATUS=$(cat "$SYSPATH/status")
CAPACITY=$(cat "$SYSPATH/charge_full")
LEVEL=$(cat "$SYSPATH/charge_now")
PERCENT=$(python -c "print($LEVEL * 100. / $CAPACITY)")
-echo -e "$STATUS\t$LEVEL/$CAPACITY ($PERCENT%)"
+echo -e "$BAT\t$STATUS\t$LEVEL/$CAPACITY ($PERCENT%)"