1
0

separate out battery frontend

This commit is contained in:
dtb 2022-08-13 16:29:04 -04:00
parent 2cb44c6fd1
commit 2446198d70
3 changed files with 20 additions and 14 deletions

View File

@ -1,18 +1,11 @@
#!/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
# battery -> battery.linux battery.netbsd etc
subprogram="$0"."$(uname | lowercase)"
if ! command -v "$subprogram" >/dev/null 2>&1 && ! test -e "$subprogram"; then
printf "%s: unsupported system\n" "$(uname)" 1>&2
exit 1
exit 70 # sysexits(3) EX_SOFTWARE
fi
"$subprogram" | exit 70 # sysexits(3) EX_SOFTWARE

6
bin/battery.linux Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# this is a dirty hack.
# acpi | awk '{print $4}' will print the battery percentage,
# and s/,$// strips the trailing comma.
acpi | awk '{print $4}' | sed 's/,$//'

7
bin/battery.netbsd Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
envstat -s acpibat0:charge \
| sed 1,2d \
| cut -d ':' -f 2 \
| awk '{print $1}' \
| cut -d '.' -f 1