summaryrefslogtreecommitdiff
path: root/sys/dwmblocks-battery
diff options
context:
space:
mode:
authorGeorge Abbott <george@gabbott.dev>2023-10-31 17:54:07 +0000
committerGeorge Abbott <george@gabbott.dev>2023-10-31 17:54:07 +0000
commit4d0bd914e7c1ee65f4036e60149a7b891906a5d3 (patch)
treec2a6751823e064e003cd4f6166df07bfc106d7eb /sys/dwmblocks-battery
Commit all to date.
Diffstat (limited to 'sys/dwmblocks-battery')
-rwxr-xr-xsys/dwmblocks-battery54
1 files changed, 54 insertions, 0 deletions
diff --git a/sys/dwmblocks-battery b/sys/dwmblocks-battery
new file mode 100755
index 0000000..455a42f
--- /dev/null
+++ b/sys/dwmblocks-battery
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+CHARGING=""
+
+get_symbol() {
+ printf ''
+ if [ "$2" = "indeed" ]; then
+ printf $CHARGING
+ else
+ if [ "$1" -ge 0 ] && [ "$1" -le 4 ]; then
+ printf ""
+ elif [ "$1" -ge 5 ] && [ "$1" -le 14 ]; then
+ printf ""
+ elif [ "$1" -ge 15 ] && [ "$1" -le 24 ]; then
+ printf ""
+ elif [ "$1" -ge 25 ] && [ "$1" -le 34 ]; then
+ printf ""
+ elif [ "$1" -ge 35 ] && [ "$1" -le 44 ]; then
+ printf ""
+ elif [ "$1" -ge 45 ] && [ "$1" -le 54 ]; then
+ printf ""
+ elif [ "$1" -ge 55 ] && [ "$1" -le 64 ]; then
+ printf ""
+ elif [ "$1" -ge 65 ] && [ "$1" -le 74 ]; then
+ printf ""
+ elif [ "$1" -ge 75 ] && [ "$1" -le 84 ]; then
+ printf ""
+ elif [ "$1" -ge 85 ] && [ "$1" -le 94 ]; then
+ printf ""
+ elif [ "$1" -ge 95 ] && [ "$1" -le 100 ]; then
+ printf ""
+ else
+ printf "uhoh"
+ fi
+ fi
+ printf ''
+
+}
+
+for bat in /sys/class/power_supply/BAT*; do
+ stt=$(cat "$bat/status")
+ if [ "$stt" = 'Discharging' ] || [ "$stt" = 'Not charging' ]
+ then
+ is_battery_charging='no'
+ else
+ is_battery_charging='indeed'
+ fi
+
+ cpcy="$(cat "$bat/capacity")"
+
+ symbol="$(get_symbol "$cpcy" "$is_battery_charging")"
+
+ printf "$symbol $cpcy%%" | tr '\n' ' ';
+done