summaryrefslogtreecommitdiff
path: root/emacs/inits/02-modeline.el
blob: aba6e9ce9480a24c45b70a9684de03ab621749fd (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
;; Time-stamp: <2020-04-24 14:49:48 (tslil@bison)>

;; -----------------------------------------------------------------------------
;; Battery status and CPU temperature

(defvar sys-status "")
(defvar sys-status-cpu-temp-threshold "45")

(defun linux-sys-status ()
  (let ((bat-s (string-trim (shell-command-to-string "~/.local/bin/battery")))
        (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 (when (functionp 'exwm-workspace-lighter) (exwm-workspace-lighter)))
          " " (: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)

  (when (symbolp exwm-workspace-switch-hook)
    (push #'minibuffer-line--update exwm-workspace-switch-hook)))

;; 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))