1
0
src/bin/battery

19 lines
528 B
Plaintext
Raw Normal View History

2022-06-26 14:46:44 -06:00
#!/bin/sh
# adapted from other script i wrote, also in the public domain
if [ "$(uname)" = "Linux" ]; then
# this is a dirty hack.
# acpi | awk '{print $4}' will print the battery percentage,
# and s/,$// strips the trailing comma.
printf "%s\n" "$(acpi | awk '{print $4}' | sed 's/,$//')"
elif [ "$(uname)" = "NetBSD" ]; then
printf "%s\n" "$(envstat -s acpibat0:charge \
| sed 1,2d \
| cut -d ':' -f 2 \
| awk '{print $1}' \
| cut -d '.' -f 1)"
else
printf "%s: unsupported system\n" "$(uname)" 1>&2
exit 1
fi