blob: 58b2cd1b8edaad2022131ca3317ba0bc9ac23986 (
plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
;; Time-stamp: <2019-08-13 14:43:24 (tslil@basingstoke)>
;; -----------------------------------------------------------------------------
;; Battery status and CPU temperature
(defvar sys-status "")
(defvar sys-status-cpu-temp-threshold "45")
(defun linux-sys-status ()
(let ((bat-s (if (not (file-exists-p "/sys/class/power_supply/sbs-20-000b/uevent")) ""
(with-temp-buffer
(insert-file-contents "/sys/class/power_supply/sbs-20-000b/uevent")
(re-search-forward "POWER_SUPPLY_STATUS=\\(Discharging\\|Charging\\|Full\\)")
(let ((status (match-string 1)))
(if (string-equal "Full" status) "Full"
(let* ((perc (progn
(re-search-forward "POWER_SUPPLY_CAPACITY=\\([0-9]+\\)")
(match-string 1)))
(field (concat "POWER_SUPPLY_TIME_TO_"
(if (string-equal "Discharging" status)
"EMPTY" "FULL")
"_AVG=\\([0-9]+\\)"))
(seconds (progn
(re-search-forward field)
(string-to-number (match-string 1))))
(hours (/ seconds 3600))
(minutes (/ (- seconds (* hours 3600)) 60)))
(format "%s%s%% %dh%dm"
(substring status 0 1)
perc hours minutes)))))))
(temp-s (if (not (file-exists-p "/sys/class/thermal/thermal_zone1/temp")) ""
(with-temp-buffer
(insert-file-contents "/sys/class/thermal/thermal_zone1/temp")
(let ((temp (substring-no-properties (buffer-string) 0 -4)))
(if (string-greaterp temp sys-status-cpu-temp-threshold)
(concat " " temp "C") ""))))))
(if (and (string-blank-p bat-s) (string-blank-p temp-s))
"" (format " [%s%s]" bat-s temp-s))))
(defun sys-status-update ()
(setq sys-status (linux-sys-status)))
(defvar sys-status-update-timer (run-at-time nil 60 'sys-status-update))
;; -----------------------------------------------------------------------------
;; Remind me of my mortality
(defun mortality ()
(format " %.4f"
(/ (float-time
(time-subtract (current-time)
(encode-time 0 0 0 DAY MONTH YEAR)))
(* 60 60 24 364.25))))
;; -----------------------------------------------------------------------------
;; Mode-line and minibuffer defaults
(use-package minibuffer-line
:ensure t
:config
(setq minibuffer-line-refresh-interval 60
minibuffer-line-format
'("" (:eval (format-time-string "%d/%H.%M"))
display-time-string
(sys-status sys-status)
(:eval (mortality))
" " (:eval (abbreviate-file-name default-directory))))
;; We redefine this function to centre the text
;; Is there a better way?
(defun minibuffer-line--update ()
(with-current-buffer minibuffer-line--buffer
(erase-buffer)
(insert (format-mode-line minibuffer-line-format 'minibuffer-line))
(setq fill-column (frame-width))
(center-line)))
(minibuffer-line-mode 1))
;; really want to hook buffer changes at all, and focus
(add-hook 'minibuffer-exit-hook #'minibuffer-line--update)
(setq global-mode-string nil)
(setq-default mode-line-format
'("" mode-line-front-space
mode-line-modified "%@"
" %l:%c %[" mode-line-buffer-identification "%] %I"
" " mode-line-modes ;; (vc-mode vc-mode)
mode-line-misc-info mode-line-end-spaces))
;; -----------------------------------------------------------------------------
;; Minions to clean mode-line
(use-package minions
:ensure t
:config
(setq minions-mode-line-lighter ":")
(minions-mode 1))
|