added battery support

This commit is contained in:
Ethan Edwards 2020-09-02 12:41:30 -04:00
parent 47fe175441
commit 3ccb5359ac

View file

@ -43,6 +43,10 @@ battery_percent()
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%') 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*) CYGWIN*|MINGW32*|MSYS*|MINGW*)
# leaving empty - TODO - windows compatability # leaving empty - TODO - windows compatability
;; ;;
@ -57,13 +61,17 @@ battery_status()
# Check OS # Check OS
case $(uname -s) in case $(uname -s) in
Linux) Linux)
status=$(linux_acpi status) status=$(linux_acpi status)
;; ;;
Darwin) Darwin)
status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2) 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*) CYGWIN*|MINGW32*|MSYS*|MINGW*)
# leaving empty - TODO - windows compatability # leaving empty - TODO - windows compatability
;; ;;
@ -72,11 +80,28 @@ battery_status()
;; ;;
esac esac
if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then case $status in
echo '' discharging|Discharging)
else echo ''
echo 'AC' ;;
fi 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() main()