swaydots

my dotfiles
git clone https://git.awy.one/swaydots.git
Log | Files | Refs | README | LICENSE

sb-battery (1249B)


      1 #!/bin/sh
      2 
      3 # Prints all batteries, their percentage remaining and an emoji corresponding
      4 # to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.).
      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     - Scroll to change adjust xbacklight." ;;
     14   4) xbacklight -inc 10 ;;
     15   5) xbacklight -dec 10 ;;
     16   8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
     17 esac
     18 
     19 # Loop through all attached batteries and format the info
     20 for battery in /sys/class/power_supply/BAT?*; do
     21   # If non-first battery, print a space separator.
     22   [ -n "${capacity+x}" ] && printf " "
     23   # Sets up the status and capacity
     24   case "$(cat "$battery/status" 2>&1)" in
     25     "Full") status="⚡" ;;
     26     "Discharging") status="🔋" ;;
     27     "Charging") status="🔌" ;;
     28     "Not charging") status="🛑" ;;
     29     "Unknown") status="♻️" ;;
     30     *) exit 1 ;;
     31   esac
     32   capacity="$(cat "$battery/capacity" 2>&1)"
     33   # Will make a warn variable if discharging and low
     34   [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
     35   # Prints the info
     36   printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn
     37 done && printf "\\n"