Merge pull request #2 from ginglis13/linux-bat

battery: add support for linux
This commit is contained in:
Dane Williams 2020-04-07 22:26:39 -07:00 committed by GitHub
commit 712a951942
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,17 +6,49 @@
battery_percent()
{
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')
# Check OS
case $(uname -s) in
Linux)
cat /sys/class/power_supply/BAT0/capacity
;;
Darwin)
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# leaving empty - TODO - windows compatability
;;
*)
;;
esac
}
battery_status()
{
status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2)
# Check OS
case $(uname -s) in
Linux)
status=$(cat /sys/class/power_supply/BAT0/status)
;;
if [ $status = 'discharging' ]; then
Darwin)
status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2)
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# leaving empty - TODO - windows compatability
;;
*)
;;
esac
if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then
echo ''
else
echo 'AC '
echo 'AC '
fi
}