Krolyxon
Commit c810e7f

Branches

Refs →

dotfiles-x11c810e7f

sb-battery

Author
krolxon
Date
2023-11-04 13:09 +0530
Parent
005b160
Commit
c810e7f091e079116080a04ba6cdd12cd0d42f2f

+37 −0

1 file changed

  1. A .local/bin/statusbar/sb-battery +37 −0
A .local/bin/statusbar/sb-battery View
@@ -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"