How to display uptime on emacs status bar? I am looking for / usr / bin / uptime to be displayed in the status bar

Am I looking for / usr / bin / uptime to display in the emacs status bar? I am using GNU Emacs 23.1.1 on centos.

thanks

+4
source share
3 answers
suggestions

@louxius deserve attention. As for the specific implementation, here is a snippet from my .emacs :

 ... ;; custom modeline (setq-default mode-line-format (list " " 'mode-line-modified ;; the "**" at the beginning "--" 'mode-line-buffer-identification ;; buffer file name "--" 'mode-line-modes ;; major and minor modes in effect 'mode-line-position ;; line, column, file % "--" '(:eval (battery-status)) "--" '(:eval (temperature)) "--" '(:eval (format-time-string "%I:%M" (current-time))) "-%-")) ;; dashes sufficient to fill rest of modeline. (defun battery-status () "Outputs the battery percentage from acpi." (replace-regexp-in-string ".*?\\([0-9]+\\)%.*" " Battery: \\1%% " (substring (shell-command-to-string "acpi") 0 -1))) (defun temperature () (replace-regexp-in-string ".*? \\([0-9\.]+\\) .*" "Temp: \\1°C " (substring (shell-command-to-string "acpi -t") 0 -1))) ... 

I want different things to be displayed there, but this should be a decent starting point for you.

+2
source

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)))) "-%-")) 
+2
source

The emacs-uptime search function. And look at the link to set the mode line.

+1
source

Source: https://habr.com/ru/post/1498009/


All Articles