Shell: Fix shell-command-duration.

master
Pierre Neidhardt 2020-05-23 15:09:33 +02:00
parent cd0b9013ca
commit 2e7829996f
1 changed files with 15 additions and 7 deletions

View File

@ -51,6 +51,10 @@ prefix arg shell buffer doesn't exists, create it and switch to it."
(call-interactively #'comint-previous-prompt)
(re-search-backward comint-prompt-regexp)
(point))
(save-excursion
;; Right result if on first char after prompt.
(re-search-backward comint-prompt-regexp)
(point))
(save-excursion
;; Right result if on prompt.
(call-interactively #'comint-next-prompt)
@ -93,13 +97,17 @@ In normal circumstances this input is additionally filtered by
(defun ambrevar/shell-command-duration ()
"Return duration of command at point in a `shell' buffer."
(interactive)
(let ((begin (parse-time-string (get-text-property
(ambrevar/shell-prompt-begin-position)
'help-echo)))
(end (parse-time-string (ambrevar/shell-prompt))))
(message "Command took %fs seconds."
(- (float-time (apply 'encode-time end))
(float-time (apply 'encode-time begin))))))
(let ((begin (ignore-errors (parse-time-string (get-text-property
(ambrevar/shell-prompt-begin-position)
'help-echo))))
(end (parse-time-string (save-excursion
(call-interactively 'comint-next-prompt)
(ambrevar/shell-prompt)))))
(if begin
(message "Command took %.0f seconds."
(- (float-time (apply 'encode-time end))
(float-time (apply 'encode-time begin))))
(message "No timestamp."))))
(defun ambrevar/shell-narrow-to-prompt ()
"Narrow buffer to prompt at point."