summaryrefslogtreecommitdiff
path: root/wm/someblocks/dwmblocks-battery
diff options
context:
space:
mode:
authorstkhan <personal@slickd.xyz>2023-03-31 19:42:29 -0500
committerstkhan <personal@slickd.xyz>2023-03-31 19:42:29 -0500
commit0e71af11a27631e45c0160842e4498507420eff0 (patch)
tree4eed4eba5b0273f26bc55243cce36a2670ac0fef /wm/someblocks/dwmblocks-battery
parent07afc07ffff324f3a355f2437bd643b616fe0af4 (diff)
bar and blocks
Diffstat (limited to 'wm/someblocks/dwmblocks-battery')
-rwxr-xr-xwm/someblocks/dwmblocks-battery21
1 files changed, 21 insertions, 0 deletions
diff --git a/wm/someblocks/dwmblocks-battery b/wm/someblocks/dwmblocks-battery
new file mode 100755
index 0000000..66f1d1f
--- /dev/null
+++ b/wm/someblocks/dwmblocks-battery
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+BAT_FILE=/sys/class/power_supply/BAT0
+
+for battery in $BAT_FILE; 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="🛑" ;;
+ *) 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"