2020-03-14 22:42:06 +01:00
|
|
|
#!/usr/bin/env bash
|
2020-05-21 17:32:20 +02:00
|
|
|
linux_acpi() {
|
|
|
|
arg=$1
|
|
|
|
BAT=$(ls -d /sys/class/power_supply/BAT* | head -1)
|
|
|
|
if [ ! -x "$(which acpi 2> /dev/null)" ];then
|
|
|
|
case "$arg" in
|
|
|
|
status)
|
|
|
|
cat $BAT/status
|
|
|
|
;;
|
2020-03-14 22:42:06 +01:00
|
|
|
|
2020-05-21 17:32:20 +02:00
|
|
|
percent)
|
|
|
|
cat $BAT/capacity
|
|
|
|
;;
|
2020-05-11 20:08:13 +02:00
|
|
|
|
2020-05-21 17:32:20 +02:00
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
case "$arg" in
|
|
|
|
status)
|
|
|
|
acpi | cut -d: -f2- | cut -d, -f1 | tr -d ' '
|
|
|
|
;;
|
|
|
|
percent)
|
|
|
|
acpi | cut -d: -f2- | cut -d, -f2 | tr -d '% '
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
2020-03-14 22:42:06 +01:00
|
|
|
battery_percent()
|
|
|
|
{
|
2020-04-07 21:52:41 +02:00
|
|
|
# Check OS
|
|
|
|
case $(uname -s) in
|
|
|
|
Linux)
|
2020-05-21 17:32:20 +02:00
|
|
|
linux_acpi percent
|
2020-04-07 21:52:41 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
Darwin)
|
|
|
|
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')
|
|
|
|
;;
|
|
|
|
|
|
|
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
|
|
|
# leaving empty - TODO - windows compatability
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2020-03-14 22:42:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
battery_status()
|
|
|
|
{
|
2020-04-07 21:52:41 +02:00
|
|
|
# Check OS
|
|
|
|
case $(uname -s) in
|
|
|
|
Linux)
|
2020-05-21 17:32:20 +02:00
|
|
|
status=$(linux_acpi status)
|
2020-04-07 21:52:41 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
Darwin)
|
|
|
|
status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2)
|
|
|
|
;;
|
|
|
|
|
|
|
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
|
|
|
# leaving empty - TODO - windows compatability
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2020-03-14 22:42:06 +01:00
|
|
|
|
2020-05-21 17:32:20 +02:00
|
|
|
if [ "$status" = "discharging" ] || [ "$status" = "Discharging" ]; then
|
2020-03-14 22:42:06 +01:00
|
|
|
echo ''
|
|
|
|
else
|
2020-04-07 21:52:41 +02:00
|
|
|
echo 'AC '
|
2020-03-14 22:42:06 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
bat_stat=$(battery_status)
|
|
|
|
bat_perc=$(battery_percent)
|
|
|
|
echo "♥ $bat_stat$bat_perc"
|
|
|
|
}
|
|
|
|
|
2020-03-15 00:57:01 +01:00
|
|
|
#run main driver program
|
2020-03-14 22:42:06 +01:00
|
|
|
main
|
|
|
|
|