fork download
  1. (defparameter *battery-file* "/proc/acpi/battery/BAT0/state")
  2.  
  3. (defun split-string (string delim)
  4. (let ((pos (position delim string)))
  5. (if (null pos)
  6. (cons string nil)
  7. (cons (subseq string 0 pos)
  8. (split-string (subseq string pos))))))
  9.  
  10. (defun get-battery-status ()
  11. (let ((remaining-charge
  12. (get-value-from-file *battery-file* "remaining capacity"))
  13. (present-rate (get-value-from-file *battery-file* "present rate")))
  14. (format t "Remaining battery time: ~a hrs" (/ (float present-rate)
  15. (float remaining-charge)))))
  16.  
  17. (defun get-value-from-file (file str)
  18. (with-open-file (stream file)
  19. (let ((parts (do ((line (read-line stream nil)
  20. (read-line stream nil)))
  21. ((or (null line)
  22. (not (null (search str line)))) line))))
  23. (if (null parts)
  24. nil
  25. (parse-integer (string-trim " " (cadr (split-string parts #\:)))
  26. :junk-allowed t)))))
  27.  
  28. (get-battery-status)
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty