25 lines
526 B
Bash
Executable file
25 lines
526 B
Bash
Executable file
#!/bin/sh
|
|
#Prints battery percentage
|
|
|
|
_bsd() {
|
|
PERCENT="$(apm | grep -o '[0-9].*%' | head -n 1)"
|
|
[ "$PERCENT" = "" ] && printf "None" && exit
|
|
echo "$PERCENT"
|
|
}
|
|
|
|
_linux() {
|
|
if ! [ -d /sys/class/power_supply/BAT* ]; then
|
|
printf "None\n"
|
|
exit 1
|
|
fi
|
|
for battery in /sys/class/power_supply/BAT?*; do
|
|
[ -n "${capacity+x}" ] && printf " "
|
|
capacity="$(cat "$battery/capacity" 2>&1)"
|
|
printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn
|
|
done && printf "\\n"
|
|
}
|
|
|
|
case $(uname) in
|
|
Linux) _linux ;;
|
|
*BSD) _bsd ;;
|
|
esac
|