i3battery compatible with multiple batteries

This commit is contained in:
Luke Smith 2018-11-04 18:56:39 -05:00
parent ccea275dc8
commit 9244feb6ab
2 changed files with 16 additions and 10 deletions

View file

@ -50,7 +50,11 @@ label=🌐
interval=10 interval=10
[battery] [battery]
command=i3battery command=i3battery BAT1
interval=5
[battery]
command=i3battery BAT0
interval=5 interval=5
[time] [time]

View file

@ -1,20 +1,22 @@
#!/bin/bash #!/bin/sh
NUM=`cat /sys/class/power_supply/BAT0/capacity` || exit # Give a battery name (e.g. BAT0) as an argument.
STATUS=`cat /sys/class/power_supply/BAT0/status`
if [ "$NUM" -ge 80 ]; then capacity=$(cat /sys/class/power_supply/"$1"/capacity) || exit
status=$(cat /sys/class/power_supply/"$1"/status)
if [ "$capacity" -ge 80 ]; then
color="#00FF00" color="#00FF00"
elif [ "$NUM" -ge 60 ]; then elif [ "$capacity" -ge 60 ]; then
color="#FFFFFF" color="#FFFFFF"
elif [ "$NUM" -ge 40 ]; then elif [ "$capacity" -ge 40 ]; then
color="#FFF600" color="#FFF600"
elif [ "$NUM" -ge 20 ]; then elif [ "$capacity" -ge 20 ]; then
color="#FFAE00" color="#FFAE00"
else else
color="#FF0000" color="#FF0000"
fi fi
[ "$STATUS" = "Charging" ] && color="#FFF" [ "$status" = "Charging" ] && color="#FFF"
echo "<span color='$color'>`sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Unknown/❓/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g" <<<"$STATUS"` `sed -e 's/$/%/' <<<"$NUM"`</span>" printf "<span color='%s'>%s %s</span>" "$color" "$(echo "$status" | sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Unknown/♻️/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g")" "$(echo "$capacity" | sed -e 's/$/%/')"