Add "force new session" eshell bind
This commit is contained in:
parent
9869e2ee27
commit
acc26e8d72
17
init.el
17
init.el
@ -448,16 +448,22 @@ DOCSTRING is an optional form that is discarded upon expansion."
|
|||||||
(concat (propertize str 'face 'font-lock-comment-face)
|
(concat (propertize str 'face 'font-lock-comment-face)
|
||||||
(propertize (cl-reduce (lambda (a b) (concat a "/" b)) components) 'face 'font-lock-doc-face))))
|
(propertize (cl-reduce (lambda (a b) (concat a "/" b)) components) 'face 'font-lock-doc-face))))
|
||||||
|
|
||||||
(defun user/open-eshell ()
|
(defun user/open-eshell (&optional force-new-session)
|
||||||
"Switch to an active unfocused `eshell' session, or start a new one."
|
"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)
|
(interactive)
|
||||||
(let ((eshell-buffer (cl-find-if (lambda (buffer)
|
(let ((eshell-buffer (cl-find-if (lambda (buffer)
|
||||||
(eq (buffer-local-value 'major-mode buffer)
|
(eq (buffer-local-value 'major-mode buffer)
|
||||||
'eshell-mode))
|
'eshell-mode))
|
||||||
(buffer-list))))
|
(buffer-list))))
|
||||||
(if eshell-buffer
|
(if eshell-buffer
|
||||||
(if (eq (current-buffer) eshell-buffer)
|
(if force-new-session
|
||||||
(eshell :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))))
|
(pop-to-buffer eshell-buffer '((display-buffer-reuse-window display-buffer-same-window))))
|
||||||
(eshell))))
|
(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-tabs-function #'tab-line-tabs-mode-buffers)
|
||||||
(tab-line-mode)))
|
(tab-line-mode)))
|
||||||
:bind
|
: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
|
;; `eshell-mode-map' is not available until the `esh-mode' module is loaded, so
|
||||||
;; the local keymap bindings are set up here
|
;; the local keymap bindings are set up here
|
||||||
|
Loading…
Reference in New Issue
Block a user