Skip to content

Instantly share code, notes, and snippets.

@jordonbiondo
Created January 26, 2015 19:49
Show Gist options
  • Select an option

  • Save jordonbiondo/220c41bc33567cb0a0be to your computer and use it in GitHub Desktop.

Select an option

Save jordonbiondo/220c41bc33567cb0a0be to your computer and use it in GitHub Desktop.
(defun battery-level ()
(string-to-number (shell-command-to-string "echo \"$(pmset -g ps | awk 'NR==2' | perl -pe 's/.*?(\\d+)%.*/\\1/')\"")))
(defvar battery-status-function 'battery-level)
(defun battery-indicator-string ()
(let* ((bat (funcall battery-status-function))
(index (cl-position-if (lambda (e) (> bat e)) '(87 75 62 50 37 25 12 7 -1)))
(symbol (nth index '("█" "▇" "▆" "▅" "▄" "▃" "▂" "▁" "!")))
(color (nth index (mapcar (lambda (c) (apply 'color-rgb-to-hex c)) (color-gradient '(.3 1 .2) '(1 .2 .1) 9)))))
(propertize symbol 'face (list :foreground color :box (if (<= bat 7) color nil)))))
(mapcar (lambda (c) (apply 'color-rgb-to-hex c)) (color-gradient '(.4 .9 .2) '(1 .2 .1) 9))
("#75d330" "#84c12d" "#93af2b" "#a39e28" "#b28c26" "#c17a23" "#d16821" "#e0561e" "#ef441c")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment