From 1247df0cce7282b8ab163962e8640678c973f1a6 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Tue, 5 Sep 2023 12:34:59 -0600 Subject: [PATCH] New battery module I no longer have devices with two batteries, so the old one is overly complicated. ACPI provides simpler output and an estimated time remaining!f --- waybar/waybar-battery.sh | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 waybar/waybar-battery.sh diff --git a/waybar/waybar-battery.sh b/waybar/waybar-battery.sh new file mode 100755 index 0000000..be147bc --- /dev/null +++ b/waybar/waybar-battery.sh @@ -0,0 +1,58 @@ +#!/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 + echo "$STATUS $LEVEL ($TIME)" +elif [[ $1 == bar ]]; then + 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="charging" + STATUS=" " + ;; + *) + STATUS="? " + ;; + esac + ;; + "Not charging") + 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 +elif [[ $1 == 'notify' ]]; then + notify-send Battery "$(echo $ACPI | cut -d':' -f2- | sed 's/\s//')" +else + echo "invalid option $1" +fi