Skip to content

Instantly share code, notes, and snippets.

@awinarko-lab
Created February 10, 2025 02:55
Show Gist options
  • Save awinarko-lab/e12867dd3361cc9ada7ec46f3d072cf9 to your computer and use it in GitHub Desktop.
Save awinarko-lab/e12867dd3361cc9ada7ec46f3d072cf9 to your computer and use it in GitHub Desktop.
Show Information of Battery Status
for bat in /sys/class/power_supply/BAT*; do
echo "Battery: $(basename "$bat")"
echo "Capacity: $(cat "$bat/capacity")%"
echo "Status: $(cat "$bat/status" 2>/dev/null)"
design_capacity=$(cat "$bat/energy_full_design" 2>/dev/null || cat "$bat/charge_full_design" 2>/dev/null)
current_capacity=$(cat "$bat/energy_full" 2>/dev/null || cat "$bat/charge_full" 2>/dev/null)
if [[ -n "$design_capacity" && -n "$current_capacity" && "$design_capacity" -gt 0 ]]; then
health=$(( current_capacity * 100 / design_capacity ))
echo "Design capacity: ${design_capacity} µWh"
echo "Current capacity: ${current_capacity} µWh"
echo "Battery health: ${health}%"
else
echo "Battery health: Unable to determine"
fi
echo "-------------------------------------"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment