Skip to content

improves the battery segment on Linux systems with multiple batteries #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025

Conversation

akunbeben
Copy link
Contributor

Hi,

This PR improves the battery segment on Linux systems by properly handling devices with multiple batteries (such as ThinkPad laptops with both internal and external batteries).

What changed:

  • Instead of checking only BAT0 or BAT1, the script now loops through all available /sys/class/power_supply/BAT* devices.
  • It sums the charge_now and charge_full (or energy_now and energy_full) values across all batteries to calculate an accurate total percentage.

Why:

On devices like the ThinkPad T480, this improves the accuracy of the battery indicator since both internal and external batteries are used together.

This change preserves existing behavior for systems with only one battery, and should be backwards compatible.

Thanks.

Screenshot from 2025-04-28 23-36-12
image

Copy link
Owner

@erikw erikw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thank you for caring about backwards compatability!

@erikw erikw linked an issue Apr 29, 2025 that may be closed by this pull request
@erikw erikw merged commit 6c96d6d into erikw:main Apr 29, 2025
1 check passed
@akunbeben akunbeben deleted the multi-batteries branch April 30, 2025 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Questions about BAT0 or BAT1 in battery.sh
2 participants