#!/usr/bin/env bash

batteries=(/sys/class/power_supply/BAT*)
# Check if any battery directories exist
found=false
for b in "${batteries[@]}"; do
    if [ -d "$b" ]; then
        found=true
        break
    fi
done

if [ "$found" = false ]; then
    echo "None"
    exit 1
fi

first=true
for battery in /sys/class/power_supply/BAT*; do
    if [ -d "$battery" ]; then
        if [ -r "$battery/capacity" ]; then
            capacity=$(<"$battery/capacity")
        else
            capacity=0
        fi
        if [ "$first" = true ]; then
            echo -n "${capacity}%"
            first=false
        else
            echo -n " ${capacity}%"
        fi
    fi
done
echo

