diff options
| author | tslil clingman <> | 2019-09-11 19:18:14 -0400 |
|---|---|---|
| committer | tslil clingman <> | 2019-09-11 19:18:14 -0400 |
| commit | ac1a4884d03fc0495c773500d8a13f84b695fa43 (patch) | |
| tree | 29e5ec49e0ce957d80d8f11a155b47840c74f488 /emacs/inits/02-modeline.el | |
Init
Diffstat (limited to 'emacs/inits/02-modeline.el')
| -rw-r--r-- | emacs/inits/02-modeline.el | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/emacs/inits/02-modeline.el b/emacs/inits/02-modeline.el new file mode 100644 index 0000000..58b2cd1 --- /dev/null +++ b/emacs/inits/02-modeline.el @@ -0,0 +1,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)) |
