diff options
-rw-r--r-- | emacs/custom/fcuny-eshell.el | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/emacs/custom/fcuny-eshell.el b/emacs/custom/fcuny-eshell.el index 6d3b1c1..a3cf178 100644 --- a/emacs/custom/fcuny-eshell.el +++ b/emacs/custom/fcuny-eshell.el @@ -67,6 +67,36 @@ multiple eshell windows easier." (insert (concat "ls")) (eshell-send-input))) +(defvar-local fcuny/eshell-output-buffer "*Exported eshell output*" + "Name of buffer with the last output of Eshell command.") + +(defvar-local fcuny/eshell-output-delimiter "---" + "Delimiter for successive `prot-eshell-export' outputs.") + +(defun fcuny/eshell--command-prompt-output () + "Capture last command prompt and its output." + (let ((beg (save-excursion + (goto-char (eshell-beginning-of-input)) + (goto-char (point-at-bol))))) + (when (derived-mode-p 'eshell-mode) + (buffer-substring-no-properties beg (eshell-end-of-output))))) + +;; https://gitlab.com/protesilaos/dotfiles/-/blob/master/emacs/.emacs.d/prot-lisp/prot-eshell.el#L114 +(defun fcuny/eshell-export () + "Produce a buffer with output of the last Eshell command. +If `fcuny/eshell-output-buffer' does not exist, create it. Else +append to it, while separating multiple outputs with +`fcuny/eshell-output-delimiter'." + (interactive) + (let ((eshell-output (fcuny/eshell--command-prompt-output))) + (with-current-buffer (get-buffer-create fcuny/eshell-output-buffer) + (goto-char (point-max)) + (unless (eq (point-min) (point-max)) + (insert (format "\n%s\n\n" fcuny/eshell-output-delimiter))) + (goto-char (point-at-bol)) + (insert eshell-output) + (switch-to-buffer-other-window (current-buffer))))) + ;; eshell time and notification (defvar-local eshell-current-command-start-time nil) @@ -93,7 +123,8 @@ multiple eshell windows easier." (eshell-mode . fcuny/eshell-current-command-time-track) (eshell-mode . eshell-smart-initialize)) :commands (eshell eshell-command) - :bind (("C-c e h" . fcuny/eshell-here)) + :bind (("C-c e h" . fcuny/eshell-here) + ("C-c e e" . fcuny/eshell-export)) :custom (eshell-scroll-to-bottom-on-input 'all) (eshell-error-if-no-glob t) |