aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorArchie Hilton (thytom) <archie.hilton1@gmail.com>2019-10-25 01:24:02 +0100
committerArchie Hilton (thytom) <archie.hilton1@gmail.com>2019-10-25 01:24:02 +0100
commit7eba91d0383d44d5520485cbb64158142866b677 (patch)
tree8aa4a18712b8f3e9d5d0abfb44cd39e5730e26dc /modules
parent2785224db7935b8b4ccab35001270b1edfedf585 (diff)
Re-wrote battery script to be faster and more efficient.
Diffstat (limited to 'modules')
-rwxr-xr-xmodules/battery55
1 files changed, 27 insertions, 28 deletions
diff --git a/modules/battery b/modules/battery
index 2802be9..4ad12ff 100755
--- a/modules/battery
+++ b/modules/battery
@@ -9,36 +9,35 @@ BATTERY_2_ICON=''
BATTERY_3_ICON=''
BATTERY_4_ICON=''
+FULL_AT=98
+
+BAT_ICON=""
+ICON=""
+
get_battery()
{
- if [ -d /sys/class/power_supply/BAT? ]; then
- ac_adapter=$(cat /sys/class/power_supply/BAT?/status)
- if [ "$ac_adapter" == "Charging" ]; then
- echo "$CHARGING_ICON"
- fi
-
- # Will show all batteries with approximate icon for remaining power.
- for x in /sys/class/power_supply/BAT?/capacity;
- do
- case "$(cat $x)" in
- 100) echo "$BATTERY_FULL_ICON" ;;
- 9[0-9]) echo "$BATTERY_FULL_ICON $(cat $x)%" ;;
- 8[0-9]|7[0-9]) echo "$BATTERY_2_ICON $(cat $x)%" ;;
- 6[0-9]|5[0-9]) echo "$BATTERY_3_ICON $(cat $x)%" ;;
- 4[0-9]|3[0-9]) echo "$BATTERY_4_ICON $(cat $x)%" ;;
- 2[0-9]|1[0-9]) if [ "$ac_adapter" == "Charging" ]; then
- echo "$BATTERY_4_ICON $(cat $x)%"
- else
- echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%"
- fi ;;
- [0-9]) if [ "$ac_adapter" == "Charging" ]; then
- echo "$BATTERY_4_ICON $(cat $x)%"
- else
- echo "$WARNING_ICON $BATTERY_4_ICON $(cat $x)%"
- fi ;;
- esac
- done
- fi
+ # The vast majority of people only use one battery.
+
+ if [ -d /sys/class/power_supply/BAT0 ]; then
+ capacity=$(cat /sys/class/power_supply/BAT0/capacity)
+ charging=$(cat /sys/class/power_supply/BAT0/status)
+ if [[ "$charging" == "Charging" ]]; then
+ ICON="$CHARGING_ICON"
+ elif [[ $capacity -le 25 ]]; then
+ ICON="$WARNING_ICON"
+ fi
+
+ if [[ $capacity -ge $FULL_AT ]]; then
+ BAT_ICON=$BATTERY_FULL_ICON
+ elif [[ $capacity -le 25 ]]; then
+ BAT_ICON=$BATTERY_4_ICON
+ elif [[ $capacity -le 50 ]]; then
+ BAT_ICON=$BATTERY_3_ICON
+ elif [[ $capacity -le $FULL_AT ]]; then
+ BAT_ICON=$BATTERY_2_ICON
+ fi
+ fi
+ echo "$ICON $BAT_ICON $capacity%"
}
get_battery