rework +eshell/open and +eshell/at-cwd
empty C-u will always maps to choosing an instance, numerics will map to numeric eshell instances. This way you can still name your instances if you really want, but instant access eshells through numeric argument is allowed and incentivised.
This commit is contained in:
@@ -58,19 +58,6 @@ Uses tramp to figure out if we're in sudo mode or not. "
|
|||||||
(eshell/cd (file-remote-p default-directory 'localname))))))
|
(eshell/cd (file-remote-p default-directory 'localname))))))
|
||||||
|
|
||||||
;; Additional functions
|
;; Additional functions
|
||||||
(defun +eshell/at-cwd (&optional arg)
|
|
||||||
"Open an instance of eshell at the current working directory.
|
|
||||||
|
|
||||||
Pass argument to `+eshell/open'."
|
|
||||||
(interactive "P")
|
|
||||||
(let ((dir (if buffer-file-name
|
|
||||||
(file-name-directory buffer-file-name)
|
|
||||||
default-directory))
|
|
||||||
(buf (+eshell/open arg)))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(eshell/cd dir)
|
|
||||||
(eshell-send-input))))
|
|
||||||
|
|
||||||
(defun +eshell/--current-instances ()
|
(defun +eshell/--current-instances ()
|
||||||
(cl-loop for buffer being the buffers
|
(cl-loop for buffer being the buffers
|
||||||
if (with-current-buffer buffer
|
if (with-current-buffer buffer
|
||||||
@@ -94,34 +81,34 @@ Pass argument to `+eshell/open'."
|
|||||||
(defun +eshell/open (&optional arg)
|
(defun +eshell/open (&optional arg)
|
||||||
"Open an instance of EShell, displaying it.
|
"Open an instance of EShell, displaying it.
|
||||||
|
|
||||||
If there exists only one instance of EShell, display it. Otherwise, prompt with
|
Numeric arguments passed into `+eshell/open' are reduced by 1 i.e. C-u 1
|
||||||
a list of open instances. If user selects an instance, display that instance.
|
+eshell/open will map to the default eshell instance, C-u 2 +eshell/open
|
||||||
Otherwise, create an instance with the name given.
|
will map to the next labelled eshell instance, etc.
|
||||||
|
|
||||||
If `arg' is non nil, then always prompt user to select an instance."
|
Any numeric or null argument is passed to the `eshell' function.
|
||||||
|
|
||||||
|
Otherwise, if C-u is used, you can select an instance to spawn."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(cond
|
(cond
|
||||||
((null arg)
|
((null arg) (eshell))
|
||||||
;; No arg => Choose a default instance
|
((numberp arg)
|
||||||
(let* ((candidates (+eshell/--current-instances))
|
(if (= arg 1)
|
||||||
(project-cand (assoc (project-prefixed-buffer-name "eshell") candidates #'string=))
|
(eshell nil)
|
||||||
(default-cand (assoc "*eshell*" candidates #'string=)))
|
(eshell (1- arg))))
|
||||||
(if-let ((cand (or project-cand default-cand)))
|
(t (+eshell/--choose-instance))))
|
||||||
(switch-to-buffer (cdr cand))
|
|
||||||
(eshell))))
|
(defun +eshell/at-cwd (&optional arg)
|
||||||
((= (car arg) 4)
|
"Open an instance of eshell at the current working directory.
|
||||||
;; Arg => Choose an instance
|
|
||||||
(+eshell/--choose-instance))
|
Pass argument to `+eshell/open'."
|
||||||
(t
|
(interactive "P")
|
||||||
;; Double arg => Choose an instance then choose the directory
|
(let ((dir (if buffer-file-name
|
||||||
(let ((instance (+eshell/--choose-instance)))
|
(file-name-directory buffer-file-name)
|
||||||
(with-current-buffer instance
|
default-directory))
|
||||||
(thread-last (read-file-name "Enter directory: ")
|
(buf (+eshell/open arg)))
|
||||||
file-name-directory
|
(with-current-buffer buf
|
||||||
list
|
(eshell/cd dir)
|
||||||
eshell/cd)
|
(eshell-send-input))))
|
||||||
(eshell-send-input))
|
|
||||||
instance))))
|
|
||||||
|
|
||||||
(provide 'eshell-additions)
|
(provide 'eshell-additions)
|
||||||
;;; eshell-additions.el ends here
|
;;; eshell-additions.el ends here
|
||||||
|
|||||||
Reference in New Issue
Block a user