Add eww/sh/values/battery.sh

This commit is contained in:
Candifloss 2024-08-01 17:24:08 +00:00
parent 20faaeea24
commit 92a972a047

102
eww/sh/values/battery.sh Normal file
View File

@ -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\"}"