Skip to content

Instantly share code, notes, and snippets.

@ajchemist
Created September 22, 2013 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajchemist/6656047 to your computer and use it in GitHub Desktop.
Save ajchemist/6656047 to your computer and use it in GitHub Desktop.
2 down vote
I don't have uptime on my system, so I can't test this for you. But it should give you an idea. Seems to work on my system with ps substituted for uptime.
Perhaps someone else will offer a simpler or cleaner solution. You might also look at call-process or start-process instead of shell-command-to-string --- start-process is async. You might also want to consider using an idle timer --- the code here can slow Emacs down considerably, since it calls uptime each time the mode line is updated.
(setq-default
mode-line-format
(list " " 'mode-line-modified
"--" 'mode-line-buffer-identification
"--" 'mode-line-modes
'mode-line-position
"--" '(:eval (shell-command-to-string "uptime"))
"-%-"))
Here is another approach, which doesn't seem to slow things down noticeably:
(defun bar ()
(with-current-buffer (get-buffer-create "foo")
(erase-buffer)
(start-process "ps-proc" "foo" "uptime")))
(setq foo (run-with-idle-timer 30 'REPEAT 'bar))
(setq-default
mode-line-format
(list " " 'mode-line-modified
"--" 'mode-line-buffer-identification
"--" 'mode-line-modes
'mode-line-position
"--" '(:eval (with-current-buffer (get-buffer-create "foo")
(buffer-substring (point-min) (point-max))))
"-%-"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment