getbat 419 B

123456789101112131415161718
  1. #!/bin/sh
  2. # get battery status in ±percentage depending on whether it's charging or not
  3. # platform specific
  4. dir=/sys/class/power_supply/BAT0
  5. # check charging status
  6. grep -q ^Charging "${dir}"/status && echo -n + || echo -n -
  7. ## Do it the hard way
  8. #printf 'scale=2; %d / %d * 100 \n' \
  9. # "$(cat "${dir}"/charge_now)" \
  10. # "$(cat "${dir}"/charge_full_design)" \
  11. # | bc \
  12. # | cut -d. -f1
  13. cat "${dir}"/capacity