2023-09-05 18:34:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
ACPI=$(acpi -b)
|
|
|
|
STATUS=$(echo $ACPI | cut -d':' -f2 | sed 's/^\s\([^,]*\),.*/\1/')
|
|
|
|
LEVEL=$(echo $ACPI | cut -d',' -f2 | sed 's/\s//g' | sed 's/%$//')
|
|
|
|
TIME=$(echo $ACPI | cut -d',' -f3 | sed 's/\s//')
|
|
|
|
CLASS="unknown"
|
|
|
|
if [[ -z $1 ]]; then
|
2023-09-16 04:56:49 +00:00
|
|
|
echo "$STATUS $LEVEL ($TIME)"
|
2023-09-05 18:34:59 +00:00
|
|
|
elif [[ $1 == bar ]]; then
|
2023-09-16 04:56:49 +00:00
|
|
|
case "$STATUS" in
|
|
|
|
"Discharging")
|
|
|
|
CLASS="discharging"
|
|
|
|
case "$LEVEL" in
|
|
|
|
[8-9][0-9])
|
|
|
|
STATUS=" "
|
|
|
|
;;
|
|
|
|
[6-7][0-9])
|
|
|
|
STATUS=" "
|
|
|
|
;;
|
|
|
|
[4-5][0-9])
|
|
|
|
STATUS=" "
|
|
|
|
;;
|
|
|
|
[2-3][0-9])
|
|
|
|
STATUS=" "
|
|
|
|
;;
|
|
|
|
1[0-9])
|
|
|
|
CLASS="low"
|
|
|
|
STATUS=" "
|
|
|
|
;;
|
|
|
|
[1-9])
|
|
|
|
CLASS="critical"
|
|
|
|
STATUS=" "
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
STATUS="? "
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
"Full")
|
|
|
|
CLASS="ac"
|
|
|
|
STATUS=" "
|
|
|
|
;;
|
|
|
|
"Charging")
|
|
|
|
CLASS="charging"
|
|
|
|
STATUS="🗲"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
STATUS="✘"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
printf '{"text":"%b%%","icon":"%b ","percentage":"%b","tooltip":"%b","class":"%b"}' "${STATUS}${LEVEL}" $STATUS $LEVEL "$TIME" $CLASS
|
|
|
|
exit
|
2023-09-05 18:34:59 +00:00
|
|
|
elif [[ $1 == 'notify' ]]; then
|
2023-09-16 04:56:49 +00:00
|
|
|
notify-send Battery "$(echo $ACPI | cut -d':' -f2- | sed 's/\s//')"
|
2023-09-05 18:34:59 +00:00
|
|
|
else
|
2023-09-16 04:56:49 +00:00
|
|
|
echo "invalid option $1"
|
2023-09-05 18:34:59 +00:00
|
|
|
fi
|