From 3ccb5359ac48d345cd5197d88653fc45753d9ecf Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Wed, 2 Sep 2020 12:41:30 -0400 Subject: [PATCH] added battery support --- scripts/battery.sh | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/scripts/battery.sh b/scripts/battery.sh index 4d57ad0..d6cae11 100755 --- a/scripts/battery.sh +++ b/scripts/battery.sh @@ -43,6 +43,10 @@ battery_percent() echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%') ;; + FreeBSD) + echo $(apm | sed '8,11d' | grep life | awk '{print $4}') + ;; + CYGWIN*|MINGW32*|MSYS*|MINGW*) # leaving empty - TODO - windows compatability ;; @@ -57,13 +61,17 @@ battery_status() # Check OS case $(uname -s) in Linux) - status=$(linux_acpi status) + status=$(linux_acpi status) ;; Darwin) status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2) ;; + FreeBSD) + status=$(apm | sed '8,11d' | grep Status | awk '{printf $3}') + ;; + CYGWIN*|MINGW32*|MSYS*|MINGW*) # leaving empty - TODO - windows compatability ;; @@ -72,11 +80,28 @@ battery_status() ;; esac - if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then - echo '' - else - echo 'AC' - fi + case $status in + discharging|Discharging) + echo '' + ;; + high) + echo '' + ;; + charging) + echo 'AC' + ;; + *) + echo 'AC' + ;; + esac + ### Old if statements didn't work on BSD, they're probably not POSIX compliant, not sure + # if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then + # echo '' + # # elif [ $status = 'charging' ]; then # This is needed for FreeBSD AC checking support + # # echo 'AC' + # else + # echo 'AC' + # fi } main()