diff options
author | Vincent Ambo <mail@tazj.in> | 2023-07-22T09·21+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-07-22T09·26+0000 |
commit | 29cc473d59c68b315b5e59ed21c6278a65c251a2 (patch) | |
tree | 4b8b284e74ffb76221c450554ceb251c07528ce5 | |
parent | 432222f098bfceb033e63e9a63687e35574457f9 (diff) |
feat(tazjin/emacs): modeline warning if tty sessions are logged in r/6440
Change-Id: I88a9ca299f82917fb5b618766aef319aa2e141fa Reviewed-on: https://cl.tvl.fyi/c/depot/+/8981 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: tazjin <tazjin@tvl.su>
-rw-r--r-- | users/tazjin/emacs/config/look-and-feel.el | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/users/tazjin/emacs/config/look-and-feel.el b/users/tazjin/emacs/config/look-and-feel.el index 0281e360d693..467316aa8b25 100644 --- a/users/tazjin/emacs/config/look-and-feel.el +++ b/users/tazjin/emacs/config/look-and-feel.el @@ -35,6 +35,35 @@ (when (bottom-right-window-p) (telephone-line-raw mode-line-misc-info t))) +;; Implements a mode-line warning if there are any logged in TTY +;; sessions apart from the graphical one. +;; +;; The status is only updated once every 30 seconds, as it requires +;; shelling out to some commands (for now). +(defun list-tty-sessions () + "List all logged in tty sessions, except tty7 (graphical)" + (let ((command "who | awk '{print $2}' | grep -v tty7")) + (-filter (lambda (s) (not (string-empty-p s))) + (s-lines + (s-trim (shell-command-to-string command)))))) + +(defvar cached-tty-sessions (cons (time-convert nil 'integer) (list-tty-sessions)) + "Cached TTY session value to avoid running the command too often.") + +(defun get-cached-tty-sessions () + (let ((time )) + (when (< 30 + (- (time-convert nil 'integer) + (car cached-tty-sessions))) + (setq cached-tty-sessions + (cons (time-convert nil 'integer) (list-tty-sessions))))) + + (cdr cached-tty-sessions)) + +(telephone-line-defsegment telephone-line-warn-tty-session () + (when-let (sessions (get-cached-tty-sessions)) + (format "W: [%s]!!" (s-join "," sessions)))) + (defun telephone-line-setup () (telephone-line-defsegment telephone-line-last-window-segment () (telephone-misc-if-last-window)) @@ -51,7 +80,8 @@ '(highlight . (special-highlight . special-highlight))) (setq telephone-line-lhs - '((nil . (telephone-line-position-segment)) + '((highlight . (telephone-line-warn-tty-session)) + (nil . (telephone-line-position-segment)) (accent . (telephone-line-buffer-segment)))) (setq telephone-line-rhs |