diff --git a/scripts/battery_graph.sh b/scripts/battery_graph.sh index 906c5e1..6a30dc9 100755 --- a/scripts/battery_graph.sh +++ b/scripts/battery_graph.sh @@ -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 diff --git a/scripts/battery_percentage.sh b/scripts/battery_percentage.sh index ed1ba18..ad36c79 100755 --- a/scripts/battery_percentage.sh +++ b/scripts/battery_percentage.sh @@ -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 } diff --git a/scripts/battery_remain.sh b/scripts/battery_remain.sh index edbf14e..a7de13e 100755 --- a/scripts/battery_remain.sh +++ b/scripts/battery_remain.sh @@ -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 } diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 523122d..ec3b5c5 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -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 }