commit 6bd07b7221cdfb0ef5a02a4e320f17769c912761 parent 3862587180e1a41df853a70f92710ad917bcefac Author: dwrz <dwrz@dwrz.net> Date: Sun, 17 Nov 2024 19:07:28 +0000 Add Emacs eshell config Diffstat:
M | emacs/init.el | | | 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 74 insertions(+), 0 deletions(-)
diff --git a/emacs/init.el b/emacs/init.el @@ -296,6 +296,80 @@ :hook (embark-collect-mode . consult-preview-at-point-mode)) +(use-package eshell + :config + (setq eshell-banner-message "" + eshell-mv-interactive-query t) + (defvar eshell-command-start-time nil + "Holds the start time of the last Eshell command.") + + (defun eshell-record-command-start-time () + "Record the start time of the current Eshell command." + (setq eshell-command-start-time (float-time))) + + (defun eshell-format-duration (elapsed) + "Format ELAPSED time into a human readable string." + (cond + ((> elapsed 3600) + (format "%.0fh %.0fm" (/ elapsed 3600) (% (/ elapsed 60) 60))) + ((> elapsed 60) + (format "%.0fm %.0fs" (/ elapsed 60) (mod elapsed 60))) + ((> elapsed 1) + (format "%.2fs" elapsed)) + (t + (format "%.2fms" (* elapsed 1000))))) + + (defun eshell-calculate-command-duration () + "Calculate the elapsed time of the last Eshell command." + (when eshell-command-start-time + (let* ((end-time (float-time)) + (elapsed (float-time (time-subtract end-time eshell-command-start-time))) + (elapsed-time-str (eshell-format-duration elapsed))) + (propertize elapsed-time-str 'face 'font-lock-comment-face)))) + + (setq eshell-prompt-function + (lambda () + "Custom Eshell prompt using colors from the active theme." + (let* ((user-face (if (= (user-uid) 0) 'error 'success)) + (host-face (if (getenv "SSH_CONNECTION") 'warning + 'font-lock-keyword-face)) + (path-face 'font-lock-type-face) + (time-face 'font-lock-comment-face) + (success-p (zerop eshell-last-command-status)) + (checkmark (if success-p "✔" "✘")) + (checkmark-face (if success-p 'success 'error)) + (command-duration (eshell-calculate-command-duration)) + (utc-time (propertize (format-time-string "%H:%M:%S " + (current-time) t) + 'face time-face))) + (concat + utc-time + (propertize (user-login-name) 'face user-face) + (propertize "@" 'face host-face) + (propertize (system-name) 'face host-face) + " " (propertize checkmark 'face checkmark-face) + " (" (or command-duration "0.00s") ") " + (propertize (abbreviate-file-name (eshell/pwd)) 'face path-face) + " $ ")))) + + (add-hook 'eshell-pre-command-hook #'eshell-record-command-start-time) + (add-hook 'eshell-post-command-hook #'eshell-calculate-command-duration) + + :hook + ((eshell-mode . (lambda () + (keymap-unset eshell-hist-mode-map "<up>" t) + (keymap-unset eshell-hist-mode-map "<down>" t) + (local-set-key (kbd "C-a") 'eshell-bol) + (local-set-key (kbd "<up>") 'previous-line) + (local-set-key (kbd "<down>") 'next-line))) + (eshell-pre-command . eshell-record-command-start-time)) + :ensure nil) + +(use-package eshell-vterm + :demand t + :after eshell + :config (eshell-vterm-mode)) + (use-package faces :config (let ((font "DejaVu Sans Mono-16"))