battery module doesn't appear if no battery

This commit is contained in:
Luke Smith 2018-08-07 12:49:22 -04:00
parent da0a7dcd22
commit 04a5d284a1

View file

@ -1,24 +1,20 @@
#!/bin/bash #!/bin/bash
NUM=$(cat /sys/class/power_supply/BAT0/capacity)
STATE=$(cat /sys/class/power_supply/BAT0/status)
colorget() { NUM=`cat /sys/class/power_supply/BAT0/capacity` || exit
if [[ $NUM -ge 80 ]]; then STATUS=`cat /sys/class/power_supply/BAT0/status`
if [ "$NUM" -ge 80 ]; then
color="#00FF00" color="#00FF00"
elif [[ $NUM -ge 60 ]]; then elif [ "$NUM" -ge 60 ]; then
color="#FFFFFF" color="#FFFFFF"
elif [[ $NUM -ge 40 ]]; then elif [ "$NUM" -ge 40 ]; then
color="#FFF600" color="#FFF600"
elif [[ $NUM -ge 20 ]]; then elif [ "$NUM" -ge 20 ]; then
color="#FFAE00" color="#FFAE00"
else else
color="#FF0000" color="#FF0000"
fi ;}
if [[ $STATE == "Charging" ]]; then
color="#ffffff"
else
colorget
fi fi
echo "<span color='$color'>$(echo $STATE | sed -e "s/,//g;s/Discharging/🔋/;s/Charging/🔌/;s/Unknown/❓/;s/Full/⚡/;s/ 0*/ /g;s/ :/ /g") $(echo $NUM | sed -e 's/$/%/')</span>" [ "$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>"