summaryrefslogtreecommitdiffstats
path: root/local/bin/sb-battery
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2023-11-25 15:50:08 -0500
committerMitsuo Tokumori <[email protected]>2023-11-25 15:50:56 -0500
commitc285ddd9d16f0038da0c036882eef7be75e2aae0 (patch)
tree7c4b75f275c2bf63dea6d5691051ea6e973def4c /local/bin/sb-battery
parent6778640f84cce092f425ad4ab9a1ec310a08f6d2 (diff)
downloaddotfiles-c285ddd9d16f0038da0c036882eef7be75e2aae0.tar.gz
dotfiles-c285ddd9d16f0038da0c036882eef7be75e2aae0.tar.bz2
dotfiles-c285ddd9d16f0038da0c036882eef7be75e2aae0.zip
Add helper scripts for dwmblocks
Diffstat (limited to 'local/bin/sb-battery')
-rwxr-xr-xlocal/bin/sb-battery37
1 files changed, 37 insertions, 0 deletions
diff --git a/local/bin/sb-battery b/local/bin/sb-battery
new file mode 100755
index 0000000..93cbe08
--- /dev/null
+++ b/local/bin/sb-battery
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# Prints all batteries, their percentage remaining and an emoji corresponding
+# to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.).
+
+case $BLOCK_BUTTON in
+ 3) notify-send "🔋 Battery module" "🔋: discharging
+🛑: not charging
+♻: stagnant charge
+🔌: charging
+⚡: charged
+❗: battery very low!
+- Scroll to change adjust xbacklight." ;;
+ 4) xbacklight -inc 10 ;;
+ 5) xbacklight -dec 10 ;;
+ 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
+esac
+
+# Loop through all attached batteries and format the info
+for battery in /sys/class/power_supply/BAT?*; do
+ # If non-first battery, print a space separator.
+ [ -n "${capacity+x}" ] && printf " "
+ # Sets up the status and capacity
+ case "$(cat "$battery/status" 2>&1)" in
+ "Full") status="⚡" ;;
+ "Discharging") status="🔋" ;;
+ "Charging") status="🔌" ;;
+ "Not charging") status="🛑" ;;
+ "Unknown") status="♻️" ;;
+ *) exit 1 ;;
+ esac
+ capacity="$(cat "$battery/capacity" 2>&1)"
+ # Will make a warn variable if discharging and low
+ [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
+ # Prints the info
+ printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn
+done && printf "\\n"