From 92a972a047f1e70ab4b7a115f486f05dc89d173a Mon Sep 17 00:00:00 2001 From: Candifloss Date: Thu, 1 Aug 2024 17:24:08 +0000 Subject: [PATCH] Add eww/sh/values/battery.sh --- eww/sh/values/battery.sh | 102 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 eww/sh/values/battery.sh diff --git a/eww/sh/values/battery.sh b/eww/sh/values/battery.sh new file mode 100644 index 0000000..e58a7c3 --- /dev/null +++ b/eww/sh/values/battery.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +c=$(cat /sys/class/power_supply/BAT0/capacity); +s=$(cat /sys/class/power_supply/BAT0/status); +s=${s//\ /} +s=${s,,} + +if [[ $c -eq 0 ]]; then + cl="empty"; +elif [[ $c -le 9 ]]; then + cl="critical"; +elif [[ $c -le 20 ]]; then + cl="vlow"; +elif [[ $c -le 40 ]]; then + cl="low"; +elif [[ $c -le 65 ]]; then + cl="medium"; +elif [[ $c -le 100 ]]; then + cl="high"; +elif [[ $c -eq 100 ]]; then + cl="full"; +else + cl="unknown"; +fi + +case "$s" in + "unknown") + ico="" + ;; + "notcharging") + ico="" + ;; + "charging") + s="$s $cl"; + case "$cl" in + "empty") + ico="" + ;; + "critical") + ico="" + ;; + "vlow") + ico="" + ;; + "low") + ico="" + ;; + "medium") + ico="" + ;; + "high") + ico="" + ;; + "full") + ico="" + ;; + "unknown") + ico="" + ;; + *) + ico="B" + ;; + esac + ;; + "discharging") + s="$s $cl"; + case "$cl" in + "empty") + ico="" + ;; + "critical") + ico="" + ;; + "vlow") + ico="" + ;; + "low") + ico="" + ;; + "medium") + ico="" + ;; + "high") + ico="" + ;; + "full") + ico="" + ;; + "unknown") + ico="" + ;; + *) + ico="B" + ;; + esac + ;; + *) + ico="B" + ;; +esac + +echo "{\"level\":\"$c\",\"status\":\"$s\",\"icon\":\"$ico\"}" \ No newline at end of file