summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eshell-conf.el88
1 files changed, 87 insertions, 1 deletions
diff --git a/eshell-conf.el b/eshell-conf.el
index d0fc491..425d5cc 100644
--- a/eshell-conf.el
+++ b/eshell-conf.el
@@ -32,6 +32,92 @@
(require 'esh-util)
(require 'ring)
+;; Measure time of commands and display automatically.
+
+;;;###autoload
+(defvar-local eshell-current-command-start-time nil
+ "The time of the start of the current command.")
+
+;;;###autoload
+(defvar-local eshell-prompt-time-string ""
+ "The string displaying the time of the last command, if any.")
+
+;;;###autoload
+(defun eshell-current-command-start ()
+ (setq-local eshell-current-command-start-time (current-time)))
+
+;;;###autoload
+(defun eshell-current-command-stop ()
+ (cond
+ ((timep eshell-current-command-start-time)
+ (let* ((elapsed-time (time-since eshell-current-command-start-time))
+ (elapsed-time-list (time-convert elapsed-time 'list))
+ (elapsed-time-int (time-convert elapsed-time 'integer))
+ (format-seconds-string
+ (format-seconds "%yy %dd %hh %mm %ss%z" elapsed-time-int))
+ (microseconds (caddr elapsed-time-list))
+ (micro-str
+ (cond ((> microseconds 10000)
+ (format "%dμs" microseconds)))))
+ (setq eshell-prompt-time-string
+ (mapconcat #'identity
+ (delq nil (list format-seconds-string
+ micro-str))
+ " "))
+ (message eshell-prompt-time-string))
+ (setq eshell-current-command-start-time nil))))
+
+;;;###autoload
+(defun eshell-current-command-time-track ()
+ (add-hook 'eshell-pre-command-hook #'eshell-current-command-start nil t)
+ (add-hook 'eshell-post-command-hook #'eshell-current-command-stop nil t))
+
+;;;###autoload
+(defun eshell-start-track-command-time ()
+ "Start tracking the time of commands."
+ (cond
+ ((derived-mode-p 'eshell-mode)
+ (eshell-current-command-time-track)))
+ (add-hook 'eshell-mode-hook #'eshell-current-command-time-track))
+
+;;;###autoload
+(defun eshell-stop-track-command-time ()
+ (remove-hook 'eshell-pre-command-hook #'eshell-current-command-start t)
+ (remove-hook 'eshell-post-command-hook #'eshell-current-command-stop t)
+ (remove-hook 'eshell-mode-hook #'eshell-current-command-time-track))
+
+;;;###autoload
+(defun durand-eshell-emit-prompt ()
+ "Emit a prompt if eshell is being used interactively.
+Add a time information at the beginning. -- Modified by Durand."
+ (when (boundp 'ansi-color-context-region)
+ (setq ansi-color-context-region nil))
+ (run-hooks 'eshell-before-prompt-hook)
+ (if (not eshell-prompt-function)
+ (set-marker eshell-last-output-end (point))
+ (let ((prompt (funcall eshell-prompt-function)))
+ (and eshell-highlight-prompt
+ (add-text-properties 0 (length prompt)
+ '(read-only t
+ font-lock-face eshell-prompt
+ front-sticky (font-lock-face read-only)
+ rear-nonsticky (font-lock-face read-only))
+ prompt))
+ (eshell-interactive-print
+ (mapconcat #'identity
+ (delq
+ nil
+ (list
+ (cond ((> (length eshell-prompt-time-string) 0)
+ (propertize eshell-prompt-time-string
+ 'font-lock-face 'modus-themes-heading-1)) )
+ prompt))
+ " "))
+ (setq eshell-prompt-time-string "")))
+ (run-hooks 'eshell-after-prompt-hook))
+
+(advice-add #'eshell-emit-prompt :override #'durand-eshell-emit-prompt)
+
;; Eshell sets the keymap in the major mode function...
;;;###autoload
@@ -90,7 +176,7 @@ Just for the completeness."
(mapconcat
(function
(lambda (mark)
- (concat mark
+ (concat (propertize mark 'font-lock-face 'modus-themes-mark-symbol)
(make-string (- max-length (length mark)) #x20)
" -> "
(file-truename (expand-file-name mark eshell-mark-directory)))))