dotfiles-x11c810e7f
sb-battery
+37 −0
1 file changed
- A .local/bin/statusbar/sb-battery +37 −0
| @@ -0,0 +1,37 @@ | |||
| 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 | + | # 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" | |