summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/battery
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/statusbar/battery')
-rwxr-xr-x.local/bin/statusbar/battery13
1 files changed, 13 insertions, 0 deletions
diff --git a/.local/bin/statusbar/battery b/.local/bin/statusbar/battery
new file mode 100755
index 0000000..e125a6c
--- /dev/null
+++ b/.local/bin/statusbar/battery
@@ -0,0 +1,13 @@
+#!/bin/sh
+for battery in /sys/class/power_supply/BAT?
+do
+ # Get its remaining capacity and charge status.
+ capacity=$(cat "$battery"/capacity) || break
+ status=$(sed "s/[Dd]ischarging/🔋/;s/[Nn]ot charging/🛑/;s/[Cc]harging/🔌/;s/[Uu]nknown/♻️/;s/[Ff]ull/⚡/" "$battery"/status)
+
+ # If it is discharging and 25% or less, we will add a ❗ as a warning.
+ [ "$capacity" -le 25 ] && [ "$status" = "🔋" ] && warn="❗"
+
+ printf "%s%s%s%% " "$status" "$warn" "$capacity"
+ unset warn
+done | sed 's/ *$//'