From 86fdf93e34b52872c7ce1d733b972d0736850891 Mon Sep 17 00:00:00 2001
From: Aryadev Chavali <aryadev@aryadevchavali.com>
Date: Sat, 5 Apr 2025 19:43:26 +0100
Subject: Fix some bugs with +eshell/open

---
 Emacs/.config/emacs/elisp/eshell-additions.el | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

(limited to 'Emacs/.config/emacs')

diff --git a/Emacs/.config/emacs/elisp/eshell-additions.el b/Emacs/.config/emacs/elisp/eshell-additions.el
index 5e637c2..a9362db 100644
--- a/Emacs/.config/emacs/elisp/eshell-additions.el
+++ b/Emacs/.config/emacs/elisp/eshell-additions.el
@@ -80,24 +80,35 @@ Otherwise, create an instance with the name given.
 
 If `arg' is non nil, then always prompt user to select an instance."
   (interactive "P")
-  (let ((current-instances (+eshell/--current-instances)))
+  (let ((current-instances (+eshell/--current-instances))
+        (buffer nil))
     (cond
      ((and (null current-instances)
            (null arg))
-      (eshell))
+      (setq buffer (eshell)))
      ((and (= (length current-instances) 1)
            (null arg))
+      (setq buffer (cdar current-instances))
       (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)))
+         (result (switch-to-buffer (cdr result))
+                 (setq buffer (cdr result)))
          ((not (string= answer ""))
           (let ((eshell-buffer-name (format "*%s-eshell*" answer)))
-            (eshell nil)))
+            (setq buffer (eshell nil))))
          (t
-          (eshell))))))))
+          (setq buffer (eshell)))))))
+    (if (and (consp arg) (> (car arg) 4))
+        (with-current-buffer buffer
+          (thread-last (read-file-name "Enter directory: ")
+                       file-name-directory
+                       list
+                       eshell/cd)
+          (eshell-send-input)))
+    buffer))
 
 (provide 'eshell-additions)
 ;;; eshell-additions.el ends here
-- 
cgit v1.2.3-13-gbd6f