I do not have uptime in my system, so I can not check this for you. But that should give you an idea. It seems ps works for my system instead of uptime .
Maybe someone else will offer a simpler or cleaner solution. You can also look at call-process or start-process instead of shell-command-to-string --- start-process isync. You can also consider using an idle timer - here the code can slow down Emacs significantly, since it calls uptime every 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's another approach that doesn't seem to slow down the slowdown:
(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)))) "-%-"))
source share