scripts

scripts to make my pc work
Index Commits Files Refs
statusbar/sb-battery (1304B)
   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     6) "$TERMINAL" -e "$EDITOR" "$0" ;;
  17 esac
  18 
  19 if [ ! -e /sys/class/power_supply/BAT?* ]; then
  20     status="🔌 " && printf "%s%s" "$status" "AC" && exit 0;
  21 fi
  22 
  23 # Loop through all attached batteries and format the info
  24 for battery in /sys/class/power_supply/BAT?*; do
  25     # If non-first battery, print a space separator.
  26     [ -n "${capacity+x}" ] && printf " "
  27     # Sets up the status and capacity
  28     case "$(cat "$battery/status")" in
  29         "Full") status="🔌";;
  30             # printf "%s %s" "$status" "AC";
  31             # exit 0;;
  32         "Discharging") status="🔋" ;;
  33         "Charging") status="⚡" ;;
  34         "Not charging") status="🛑" ;;
  35         "Unknown") status="♻️ " ;;
  36     esac
  37     capacity=$(cat "$battery/capacity")
  38     # Will make a warn variable if discharging and low
  39     [ "$status" = "🔋" ] && [ "$capacity" -le 20 ] && status="❗"
  40 
  41     # Prints the info
  42     printf "%s%*d%%" "$status" "3" "$capacity";
  43 done && exit 0