tmux-plugins / tmux-battery

Plug and play battery percentage and icon indicator for Tmux.
MIT License
503 stars 98 forks source link

Display all batteries that upower knows about #7

Closed JanAhrens closed 9 years ago

JanAhrens commented 9 years ago

My laptop has two batteries: One exchangeable and a built-in one. The exchangeable battery will unload before the internal. Unfortunately BAT0 is the internal battery and BAT1 is the external one. Without this patch, battery_percentage.sh displays 100% until the exchangeable battery ran out of power.

I'm suggesting to display all batteries that upower knows about. With this patch all batteries percentage levels will be displayed with a seperating space: "14% 85%".

If there is only one battery, the behavior of this script does not change. The for-loop will yield exactly one line and xargs echo won't change it.

I tested this on my system by pretending what would happen if it had only one battery.

for battery in $(upower -e | grep battery | head -1); do \
  upower -i $battery | grep percentage | awk '{print $2}'; \
done | xargs echo

This is how the upower -e output looks on my machine:

$ upower -e
/org/freedesktop/UPower/devices/line_power_AC
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/battery_BAT1
JanAhrens commented 9 years ago

I decided to add my changes to battery_icon.sh to this pull-request, because they concern the same feature: multi battery support for upower. If you like to discuss this in seperate pull-requests I'm happy to create those.

bruno- commented 9 years ago

Thanks, this is a nice feature and the code is not that complex at all.

bruno- commented 9 years ago

I've added you to the list of contributors in the readme.