commit ed6c30c23265b488b4731e1453cdf47685b73781 parent b01b7bfdf438a433b11c5c6afea8a226a1a58fda Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Thu, 26 Sep 2019 11:58:41 +0200 Show battery info on OpenBSD Diffstat:
M | .local/bin/sysstatus | | | 17 | ++++++++++++----- |
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/.local/bin/sysstatus b/.local/bin/sysstatus @@ -1,5 +1,4 @@ #!/bin/sh -battery=BAT0 separator="|" @@ -31,17 +30,25 @@ fi if [ -f /proc/loadavg ]; then printf "%s" "$(cut -f 1 -d' ' /proc/loadavg)" else - printf "%s" "$(uptime | cut -f 10 -d' ' | sed 's/,$//')" + printf "%s" "$(uptime | sed 's/.*: \([0-9]*\.[0-9]*\),.*/\1/')" fi -if [ -d "/sys/class/power_supply/$battery" ]; then +printf " $separator" + +# battery +if type apm >/dev/null 2>&1; then + printf " %s" "$(apm | grep -o -E "[0-9]*%")" + printf " %s" "$(apm | grep -o -E "[0-9]* min")" + printf " $separator" +elif [ -d "/sys/class/power_supply/$battery" ]; then + battery=BAT0 batstatus=$(sed -n 's/Charging/+/;s/Discharging/-/' \ /sys/class/power_supply/${battery}/status | sed 's/Unknown//') batlvl=$(cat /sys/class/power_supply/${battery}/capacity) batremain=$(acpi -b | sed 1q |\ sed -n 's/.*\([0-9][0-9]:[0-9][0-9]\):[0-9][0-9].*$/\1/p') - printf "%s" "$(echo "${batstatus}${batlvl}% ${batremain}" | sed 's/ $//')" + printf " %s" "$(echo "${batstatus}${batlvl}% ${batremain}" | sed 's/ $//')" + printf " $separator" fi -printf " $separator" # wlan if type ifconfig >/dev/null 2>&1; then