From 4d0bd914e7c1ee65f4036e60149a7b891906a5d3 Mon Sep 17 00:00:00 2001
From: George Abbott <george@gabbott.dev>
Date: Tue, 31 Oct 2023 17:54:07 +0000
Subject: Commit all to date.

---
 sys/dwmblocks-battery | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100755 sys/dwmblocks-battery

(limited to 'sys/dwmblocks-battery')

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
-- 
cgit v1.2.1