Rework +eshell/open to work better with multiple instances.
This commit is contained in:
@@ -68,23 +68,33 @@
|
|||||||
collect
|
collect
|
||||||
(cons (buffer-name buffer) buffer)))
|
(cons (buffer-name buffer) buffer)))
|
||||||
|
|
||||||
(defun +eshell/open (&optional ARG)
|
(defun +eshell/open (&optional arg)
|
||||||
"If no arg is given, run EShell as per usual.
|
"Open an instance of EShell, displaying it.
|
||||||
If an arg is given, then interactively open a new Eshell instance
|
|
||||||
or a currently opened one, naming it in the process."
|
If there exists only one instance of EShell, display it. Otherwise, prompt with
|
||||||
|
a list of open instances. If user selects an instance, display that instance.
|
||||||
|
Otherwise, create an instance with the name given.
|
||||||
|
|
||||||
|
If `arg' is non nil, then always prompt user to select an instance."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(if (null ARG)
|
(let ((current-instances (+eshell/--current-instances)))
|
||||||
(eshell)
|
(cond
|
||||||
(let* ((current-instances (+eshell/--current-instances))
|
((and (null current-instances)
|
||||||
(answer (completing-read "Enter name: " (mapcar #'car current-instances)))
|
(null arg))
|
||||||
(result (assoc answer current-instances)))
|
(eshell))
|
||||||
(cond
|
((and (= (length current-instances) 1)
|
||||||
(result (switch-to-buffer (cdr result)))
|
(null arg))
|
||||||
((not (string= answer ""))
|
(switch-to-buffer (cdar current-instances)))
|
||||||
(let ((eshell-buffer-name (format "*%s-eshell*" answer)))
|
(t
|
||||||
(eshell t)))
|
(let* ((answer (completing-read "Enter name: " (mapcar #'car current-instances)))
|
||||||
(t
|
(result (assoc answer current-instances)))
|
||||||
(eshell))))))
|
(cond
|
||||||
|
(result (switch-to-buffer (cdr result)))
|
||||||
|
((not (string= answer ""))
|
||||||
|
(let ((eshell-buffer-name (format "*%s-eshell*" answer)))
|
||||||
|
(eshell nil)))
|
||||||
|
(t
|
||||||
|
(eshell))))))))
|
||||||
|
|
||||||
(provide 'eshell-additions)
|
(provide 'eshell-additions)
|
||||||
;;; eshell-additions.el ends here
|
;;; eshell-additions.el ends here
|
||||||
|
|||||||
Reference in New Issue
Block a user