dotfiles/local/bin/sb-battery

26 lines
526 B
Text
Raw Normal View History

2025-05-29 23:14:16 +02:00
#!/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