My dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.2 KiB

  1. #!/bin/sh
  2. # Prints all batteries, their percentage remaining and an emoji corresponding
  3. # to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.).
  4. case $BUTTON in
  5. 3) notify-send "🔋 Battery module" "🔋: discharging
  6. 🛑: not charging
  7. ♻: stagnant charge
  8. 🔌: charging
  9. ⚡: charged
  10. ❗: battery very low!
  11. - Scroll to change adjust xbacklight." ;;
  12. 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
  13. esac
  14. # acpi alternative
  15. # 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
  16. # Loop through all attached batteries.
  17. for battery in /sys/class/power_supply/BAT?
  18. do
  19. # Get its remaining capacity and charge status.
  20. capacity=$(cat "$battery"/capacity 2>/dev/null) || break
  21. status=$(sed "s/[Dd]ischarging/🔋/;s/[Nn]ot charging/🛑/;s/[Cc]harging/🔌/;s/[Uu]nknown/♻️/;s/[Ff]ull/⚡/" "$battery"/status)
  22. # If it is discharging and 25% or less, we will add a ❗ as a warning.
  23. [ "$capacity" -le 25 ] && [ "$status" = "🔋" ] && warn="❗"
  24. printf "%s%s%s%% " "$status" "$warn" "$capacity"
  25. unset warn
  26. done | sed 's/ *$//'