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