pfr Here you go
Make it executable and move it to /usr/pkg/bin
#!/bin/sh
#
# batstate
#
# Simple battery detection tool for NetBSD
# Define variables
charge_state="$(envstat -d acpibat0 | awk 'FNR == 10 {print $2}')"
bat_perc="$(envstat -d acpibat0 | awk 'FNR == 7 {print $6}' | tr -d '()')"
# State detection
if [ "${charge_state}" = "TRUE" ]; then
Bat='charging'
else
Bat='discharging'
fi
# Output
cat <<EOF
${Bat} ${bat_perc}
EOF
Result...
pin@mybox $ batstate
charging 98.99%
pin@mybox $
or...
pin@mybox $ batstate
discharging 96.62%
pin@mybox $
😁