dwmb-battery (1059B) - raw


      1 #!/bin/sh
      2 
      3 # Prints all batteries, their percentage remaining and an emoji corresponding
      4 # to charge status.
      5 
      6 case $BLOCK_BUTTON in
      7 	3) notify-send "  Battery module" " : discharging
      8  : not charging
      9  : stagnant charge
     10  : charging
     11  : charged
     12  : battery very low!" ;;
     13 esac
     14 
     15 # acpi alternative
     16 # acpi | sed "s/Battery [0-9]: //;s/[Dd]ischarging, / /;s/[Nn]ot charging, / /;s/[Cc]harging, / /;s/[Uu]nknown, /♻️/;s/[Ff]ull, / /;s/ \(remaining\|until charged\)//"; exit
     17 
     18 # Loop through all attached batteries.
     19 for battery in /sys/class/power_supply/BAT?
     20 do
     21 	# Get its remaining capacity and charge status.
     22 	capacity=$(cat "$battery"/capacity 2>/dev/null) || break
     23 	status=$(sed "s/[Dd]ischarging/ /;s/[Nn]ot charging/ /;s/[Cc]harging/ /;s/[Uu]nknown/♻️/;s/[Ff]ull/ /" "$battery"/status)
     24 
     25 	# If it is discharging and 25% or less, we will add a   as a warning.
     26 	 [ "$capacity" -le 25 ] && [ "$status" = " " ] && warn=" "
     27 
     28 	printf "%s%s%s%%" " $status" "$warn" "$capacity"
     29 	unset warn
     30 done | sed 's/ *$//'