battery.sh 578 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. SLEEP_SEC=20
  3. xclock -digital -strftime "" -g 60x20-0-0 -fg black -bg gray80 -padding 2 -face "DejaVu Sans Mono:pixelsize=14" &
  4. PID=$!
  5. while ( true ); do
  6. BAT=`envstat -d acpibat0 | awk '
  7. BEGIN {
  8. p = "0%";
  9. s = "-";
  10. }
  11. $6 != Unit && $6 != "" {
  12. p=substr($6, 2, length($6)-2);
  13. }
  14. $1 == "charging" {
  15. if($2 == "TRUE")
  16. s = "+";
  17. }
  18. END {
  19. printf("%s%s", s,p);
  20. }'`
  21. kill $PID
  22. xclock -digital -strftime "$BAT" -g 60x20-0-0 -fg black -bg gray80 -padding 2 -face "DejaVu Sans Mono:pixelsize=14" &
  23. PID=$!
  24. sleep $SLEEP_SEC
  25. done
  26. #while :; do
  27. # sleep $SLEEP_SEC
  28. #done