adds support for OpenBSD apm. (#77)

This commit is contained in:
Franz Bettag 2019-03-11 11:05:40 +01:00 committed by Martin Beentjes
parent cc18faec34
commit 588a941cde
4 changed files with 43 additions and 1 deletions

View file

@ -22,6 +22,10 @@ print_graph() {
main() {
local percentage=$($CURRENT_DIR/battery_percentage.sh)
print_graph ${percentage%?}
if [ "$(uname)" == "OpenBSD" ]; then
print_graph ${percentage}
else
print_graph ${percentage%?}
fi
}
main

View file

@ -30,6 +30,8 @@ print_battery_percentage() {
acpi -b | grep -m 1 -Eo "[0-9]+%"
elif command_exists "termux-battery-status"; then
termux-battery-status | jq -r '.percentage' | awk '{printf("%d%%", $1)}'
elif command_exists "apm"; then
apm -l
fi
}

View file

@ -20,6 +20,32 @@ battery_charged() {
[[ $status =~ (charged) ]]
}
convertmins() {
((h=${1}/60))
((m=${1}%60))
printf "%02d:%02d\n" $h $m $s
}
apm_battery_remaining_time() {
local remaining_time="$(convertmins $(apm -m))"
if battery_discharging; then
if $short; then
echo $remaining_time | awk '{printf "~%s", $1}'
else
echo $remaining_time | awk '{printf "- %s left", $1}'
fi
elif battery_charged; then
if $short; then
echo $remaining_time | awk '{printf "charged", $1}'
else
echo $remaining_time | awk '{printf "fully charged", $1}'
fi
else
echo "charging"
fi
}
pmset_battery_remaining_time() {
local status="$(pmset -g batt)"
if echo $status | grep 'no estimate' >/dev/null 2>&1; then
@ -90,6 +116,8 @@ print_battery_remain() {
upower_battery_remaining_time
elif command_exists "acpi"; then
acpi_battery_remaining_time
elif command_exists "apm"; then
apm_battery_remaining_time
fi
}

View file

@ -38,5 +38,13 @@ battery_status() {
acpi -b | awk '{gsub(/,/, ""); print tolower($3); exit}'
elif command_exists "termux-battery-status"; then
termux-battery-status | jq -r '.status' | awk '{printf("%s%", tolower($1))}'
elif command_exists "apm"; then
local battery
battery=$(apm -a)
if [ $battery -eq 0 ]; then
echo "discharging"
elif [ $battery -eq 1 ]; then
echo "charging"
fi
fi
}