Candyrice/eww/sh/values/battery.sh

102 lines
1.5 KiB
Bash

#!/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\"}"