Introduce function to open eshell in current directory
This commit is contained in:
parent
45e5e5a9fc
commit
71e4cee886
3
init.el
3
init.el
@ -2789,6 +2789,7 @@ Note that this workaround is incomplete, as explained in this comment."
|
||||
|
||||
(use-package db-eshell
|
||||
:commands (db/run-or-hide-project-eshell
|
||||
db/run-or-hide-project-eshell-here
|
||||
eshell-clear-buffer
|
||||
eshell/default-prompt-function
|
||||
pcomplete/git))
|
||||
@ -3122,7 +3123,7 @@ Note that this workaround is incomplete, as explained in this comment."
|
||||
;; Top-Level Keybindings
|
||||
|
||||
(bind-key "<Scroll_Lock>" 'scroll-lock-mode)
|
||||
(bind-key "<f1>" #'db/run-or-hide-project-eshell)
|
||||
(bind-key "<f1>" #'db/run-or-hide-project-eshell-here)
|
||||
(bind-key "<f2>" #'db/frequently-used-features-prefix)
|
||||
(bind-key "<f5>" #'project-find-regexp)
|
||||
(bind-key "<f6>" #'text-scale-adjust)
|
||||
|
||||
@ -34,6 +34,35 @@ eshell instance is started via `project-eshell'."
|
||||
(bury-buffer)
|
||||
(delete-window))))
|
||||
|
||||
(defun db/run-or-hide-project-eshell-here ()
|
||||
"Opens an eshell buffer in the current directory.
|
||||
|
||||
The current directory is determined by the file name associated with the
|
||||
current buffer, or `default-directory'.
|
||||
|
||||
Switch to an existing eshell buffer open in the current directory.
|
||||
Create an eshell buffer otherwise."
|
||||
(interactive)
|
||||
(if (not (derived-mode-p 'eshell-mode))
|
||||
(let* ((cwd (or (file-name-directory (buffer-file-name (current-buffer)))
|
||||
default-directory))
|
||||
(eshell-buffer (--> (buffer-list)
|
||||
(-filter #'(lambda (buf)
|
||||
(with-current-buffer buf
|
||||
(and (derived-mode-p 'eshell-mode)
|
||||
(file-equal-p cwd default-directory))))
|
||||
it)
|
||||
(sort it :key #'buffer-name))))
|
||||
(if eshell-buffer
|
||||
(--if-let (display-buffer (-first-item eshell-buffer))
|
||||
(select-window it)
|
||||
(error "Cannot display existing eshell buffer"))
|
||||
(let ((default-directory cwd))
|
||||
(eshell t))))
|
||||
(progn
|
||||
(bury-buffer)
|
||||
(delete-window))))
|
||||
|
||||
(defun eshell-clear-buffer ()
|
||||
"Clear terminal."
|
||||
(interactive)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user