diff --git a/.config/i3blocks/config b/.config/i3blocks/config index 9916f96..e5a6cf8 100644 --- a/.config/i3blocks/config +++ b/.config/i3blocks/config @@ -50,7 +50,11 @@ label=🌐 interval=10 [battery] -command=i3battery +command=i3battery BAT1 +interval=5 + +[battery] +command=i3battery BAT0 interval=5 [time] diff --git a/.scripts/i3battery b/.scripts/i3battery index b25718d..6f045fc 100755 --- a/.scripts/i3battery +++ b/.scripts/i3battery @@ -1,20 +1,22 @@ -#!/bin/bash +#!/bin/sh -NUM=`cat /sys/class/power_supply/BAT0/capacity` || exit -STATUS=`cat /sys/class/power_supply/BAT0/status` +# Give a battery name (e.g. BAT0) as an argument. -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" -elif [ "$NUM" -ge 60 ]; then +elif [ "$capacity" -ge 60 ]; then color="#FFFFFF" -elif [ "$NUM" -ge 40 ]; then +elif [ "$capacity" -ge 40 ]; then color="#FFF600" -elif [ "$NUM" -ge 20 ]; then +elif [ "$capacity" -ge 20 ]; then color="#FFAE00" else color="#FF0000" fi -[ "$STATUS" = "Charging" ] && color="#FFF" +[ "$status" = "Charging" ] && color="#FFF" -echo "`sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Unknown/❓/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g" <<<"$STATUS"` `sed -e 's/$/%/' <<<"$NUM"`" +printf "%s %s" "$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/$/%/')"