summaryrefslogtreecommitdiffstats
path: root/.local/bin/statusbar/sb-battery
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2020-12-25 08:02:50 -0500
committerLuke Smith <luke@lukesmith.xyz>2020-12-25 08:02:50 -0500
commit2619a88fcd94cbd4b2caa719ba926ae0013fb4ec (patch)
treeacb240c6afee6a3ee15cf64c9788b5ed053ebe97 /.local/bin/statusbar/sb-battery
parent741e9298bd7b0dabeea26dfe039274afca572f6d (diff)
downloadeibhear-2619a88fcd94cbd4b2caa719ba926ae0013fb4ec.tar.gz
eibhear-2619a88fcd94cbd4b2caa719ba926ae0013fb4ec.tar.zst
eibhear-2619a88fcd94cbd4b2caa719ba926ae0013fb4ec.zip
statusbar scripts now with sb- to avoid conflicts
update dwmblocks build to avoid errors
Diffstat (limited to '.local/bin/statusbar/sb-battery')
-rwxr-xr-x.local/bin/statusbar/sb-battery39
1 files changed, 39 insertions, 0 deletions
diff --git a/.local/bin/statusbar/sb-battery b/.local/bin/statusbar/sb-battery
new file mode 100755
index 0000000..d0272ec
--- /dev/null
+++ b/.local/bin/statusbar/sb-battery
@@ -0,0 +1,39 @@
+#!/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
+
+# Check if battery directories are detected
+[ ! -e /sys/class/power_supply/BAT?* ] && echo "No battery found" && exit 1
+
+# Loop through all attached batteries and format the info
+for battery in /sys/class/power_supply/BAT?*
+do
+ # Sets up the status and capacity
+ status=$(cat "$battery/status")
+ case "$status" in
+ "Full") status="⚡" ;;
+ "Discharging") status="🔋" ;;
+ "Charging") status="🔌" ;;
+ "Not charging") status="🛑" ;;
+ "Unknown") status="♻️" ;;
+ esac
+ capacity=$(cat "$battery/capacity")
+ # Will make a warn variable if discharging and low
+ [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
+ # Prints the info
+ printf "%s%s%d%%\n" "$status" "$warn" "$capacity"; unset warn
+done && return 0