diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-10-16 16:31:49 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-10-16 16:32:58 +0100 |
commit | 930d35965741524ce9ae30668c5d89559d23ce1a (patch) | |
tree | b87558af53577c1ea5a144f7ed01dbf6c3c45c74 | |
parent | 7340679982c5c4062ee9f4e8333f2689c3fdcfb5 (diff) | |
download | dotfiles-930d35965741524ce9ae30668c5d89559d23ce1a.tar.gz dotfiles-930d35965741524ce9ae30668c5d89559d23ce1a.tar.bz2 dotfiles-930d35965741524ce9ae30668c5d89559d23ce1a.zip |
Rework +eshell/open to work better with multiple instances.
-rw-r--r-- | Emacs/.config/emacs/elisp/eshell-additions.el | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/Emacs/.config/emacs/elisp/eshell-additions.el b/Emacs/.config/emacs/elisp/eshell-additions.el index f22f05e..0abaf6a 100644 --- a/Emacs/.config/emacs/elisp/eshell-additions.el +++ b/Emacs/.config/emacs/elisp/eshell-additions.el @@ -68,23 +68,33 @@ collect (cons (buffer-name buffer) buffer))) -(defun +eshell/open (&optional ARG) - "If no arg is given, run EShell as per usual. -If an arg is given, then interactively open a new Eshell instance -or a currently opened one, naming it in the process." +(defun +eshell/open (&optional arg) + "Open an instance of EShell, displaying it. + +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") - (if (null ARG) - (eshell) - (let* ((current-instances (+eshell/--current-instances)) - (answer (completing-read "Enter name: " (mapcar #'car current-instances))) - (result (assoc answer current-instances))) - (cond - (result (switch-to-buffer (cdr result))) - ((not (string= answer "")) - (let ((eshell-buffer-name (format "*%s-eshell*" answer))) - (eshell t))) - (t - (eshell)))))) + (let ((current-instances (+eshell/--current-instances))) + (cond + ((and (null current-instances) + (null arg)) + (eshell)) + ((and (= (length current-instances) 1) + (null arg)) + (switch-to-buffer (cdar current-instances))) + (t + (let* ((answer (completing-read "Enter name: " (mapcar #'car current-instances))) + (result (assoc answer current-instances))) + (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) ;;; eshell-additions.el ends here |