1

Add "force new session" eshell bind

This commit is contained in:
Jessie Hildebrandt 2023-01-26 05:49:18 -05:00
parent 9869e2ee27
commit acc26e8d72

17
init.el
View File

@ -448,16 +448,22 @@ DOCSTRING is an optional form that is discarded upon expansion."
(concat (propertize str 'face 'font-lock-comment-face)
(propertize (cl-reduce (lambda (a b) (concat a "/" b)) components) 'face 'font-lock-doc-face))))
(defun user/open-eshell ()
"Switch to an active unfocused `eshell' session, or start a new one."
(defun user/open-eshell (&optional force-new-session)
"Focus the last active `eshell' session, or start a new one if none unavaiable.
When FORCE-NEW-SESSION is non-nil, a new session will be started even if there
is already an active session to switch to or focus."
(interactive)
(let ((eshell-buffer (cl-find-if (lambda (buffer)
(eq (buffer-local-value 'major-mode buffer)
'eshell-mode))
(buffer-list))))
(if eshell-buffer
(if (eq (current-buffer) eshell-buffer)
(eshell :new-session)
(if force-new-session
(let ((current-buffer-directory default-directory))
(pop-to-buffer eshell-buffer '((display-buffer-reuse-window display-buffer-same-window)))
(let ((default-directory current-buffer-directory))
(eshell :new-session)))
(pop-to-buffer eshell-buffer '((display-buffer-reuse-window display-buffer-same-window))))
(eshell))))
@ -488,7 +494,8 @@ DOCSTRING is an optional form that is discarded upon expansion."
tab-line-tabs-function #'tab-line-tabs-mode-buffers)
(tab-line-mode)))
:bind
("C-c RET" . user/open-eshell))
("C-c RET" . user/open-eshell)
("C-c C-<return>" . (lambda () (interactive) (user/open-eshell :force-new-session))))
;; `eshell-mode-map' is not available until the `esh-mode' module is loaded, so
;; the local keymap bindings are set up here