 (defun +eshell/open (&optional command)
   "Open eshell in the current buffer."
   (interactive)
-  (let ((buf (+eshell-get-or-create-buffer)))
+  (let ((buf (+eshell--buffer (eq major-mode 'eshell-mode))))
     (with-current-buffer buf
       (unless (eq major-mode 'eshell-mode) (eshell-mode)))
     (switch-to-buffer buf)

;;

;;;###autoload
(defun +eshell|init ()
  "Keep track of eshell buffers."
  (let ((buf (current-buffer)))
    (remove-hook 'kill-buffer-query-functions #'doom|protect-visible-buffers t)
    (add-hook 'kill-buffer-hook #'+eshell-delete-window nil t)
    (dolist (buf (ring-elements +eshell-buffers))
      (unless (buffer-live-p buf)
        (+eshell--remove-buffer buf)))

(defun +eshell/open-popup (&optional command)
  "Open eshell in a popup window."
  (interactive)
  (let ((buf (+eshell--buffer)))
    (with-current-buffer buf
      (unless (eq major-mode 'eshell-mode) (eshell-mode)))
    (pop-to-buffer buf)
