-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmacs-display-cpu-mem-in-the-modeline-right-corner
45 lines (39 loc) · 1.61 KB
/
Emacs-display-cpu-mem-in-the-modeline-right-corner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(defun cpu-memory-usage ()
"Display CPU/MEM Usage"
(shell-command-to-string "ps -A -o pcpu | tail -n+2 | paste -sd+ | bc | tr -cd '\40-\176' && echo ' '| tr -cd '\40-\176' && free -t --mega | grep Mem | awk '{print $1,$7}' | tr -cd '\40-\176'"))
(setq mode-line-end-spaces
(list
(propertize "Cpu: " 'face 'bold)
'(:eval (propertize (cpu-memory-usage-3) 'face 'bold))
" "))
(defun my-mode-line/padding ()
(let ((r-length (length (format-mode-line mode-line-end-spaces))))
(propertize " "
'display `(space :align-to (- right ,r-length)))))
(setq-default mode-line-format
(list
" %+ "
(propertize "%b " 'face 'bold)
"%o "
"- "
"[Mode:%m] - "
'(:eval (propertize (format-time-string "%a %D %R") 'face 'bold))
'(:eval (my-mode-line/padding))
mode-line-end-spaces))
;; if the above does not work run it only with the code below. The CPU/MEM wont be displayed in the right corner :(
;; Display CPU/MEM usage in the mode line
(defun cpu-memory-usage ()
"Display CPU/MEM Usage"
(shell-command-to-string "ps -A -o pcpu | tail -n+2 | paste -sd+ | bc | tr -cd '\40-\176' && echo ' '| tr -cd '\40-\176' && free -t --mega | grep Mem | awk '{print $1,$7}' | tr -cd '\40-\176'"))
(setq-default mode-line-format
(list
" %+ "
(propertize "%b " 'face 'bold)
"- "
"%o "
"- "
"[Mode:%m] - "
'(:eval (propertize (format-time-string "%a %D %R") 'face 'bold))
" - "
(propertize "Cpu: " 'face 'bold)
'(:eval (propertize (cpu-memory-usage) 'face 'bold))))