Skip to content

Commit 588a941

Browse files
fbettagmartinbeentjes
authored andcommitted
adds support for OpenBSD apm. (#77)
1 parent cc18fae commit 588a941

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

scripts/battery_graph.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ print_graph() {
2222

2323
main() {
2424
local percentage=$($CURRENT_DIR/battery_percentage.sh)
25-
print_graph ${percentage%?}
25+
if [ "$(uname)" == "OpenBSD" ]; then
26+
print_graph ${percentage}
27+
else
28+
print_graph ${percentage%?}
29+
fi
2630
}
2731
main

scripts/battery_percentage.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ print_battery_percentage() {
3030
acpi -b | grep -m 1 -Eo "[0-9]+%"
3131
elif command_exists "termux-battery-status"; then
3232
termux-battery-status | jq -r '.percentage' | awk '{printf("%d%%", $1)}'
33+
elif command_exists "apm"; then
34+
apm -l
3335
fi
3436
}
3537

scripts/battery_remain.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@ battery_charged() {
2020
[[ $status =~ (charged) ]]
2121
}
2222

23+
24+
convertmins() {
25+
((h=${1}/60))
26+
((m=${1}%60))
27+
printf "%02d:%02d\n" $h $m $s
28+
}
29+
30+
apm_battery_remaining_time() {
31+
local remaining_time="$(convertmins $(apm -m))"
32+
if battery_discharging; then
33+
if $short; then
34+
echo $remaining_time | awk '{printf "~%s", $1}'
35+
else
36+
echo $remaining_time | awk '{printf "- %s left", $1}'
37+
fi
38+
elif battery_charged; then
39+
if $short; then
40+
echo $remaining_time | awk '{printf "charged", $1}'
41+
else
42+
echo $remaining_time | awk '{printf "fully charged", $1}'
43+
fi
44+
else
45+
echo "charging"
46+
fi
47+
}
48+
2349
pmset_battery_remaining_time() {
2450
local status="$(pmset -g batt)"
2551
if echo $status | grep 'no estimate' >/dev/null 2>&1; then
@@ -90,6 +116,8 @@ print_battery_remain() {
90116
upower_battery_remaining_time
91117
elif command_exists "acpi"; then
92118
acpi_battery_remaining_time
119+
elif command_exists "apm"; then
120+
apm_battery_remaining_time
93121
fi
94122
}
95123

scripts/helpers.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,13 @@ battery_status() {
3838
acpi -b | awk '{gsub(/,/, ""); print tolower($3); exit}'
3939
elif command_exists "termux-battery-status"; then
4040
termux-battery-status | jq -r '.status' | awk '{printf("%s%", tolower($1))}'
41+
elif command_exists "apm"; then
42+
local battery
43+
battery=$(apm -a)
44+
if [ $battery -eq 0 ]; then
45+
echo "discharging"
46+
elif [ $battery -eq 1 ]; then
47+
echo "charging"
48+
fi
4149
fi
4250
}

0 commit comments

Comments
 (0)