mirror of
https://github.com/tmux-plugins/tmux-battery.git
synced 2026-09-10 07:26:19 -04:00
adds support for OpenBSD apm. (#77)
This commit is contained in:
parent
cc18faec34
commit
588a941cde
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue