   (let ((buf (+eshell-get-or-create-buffer)))
     (with-current-buffer buf
       (unless (eq major-mode 'eshell-mode) (eshell-mode)))
-    (switch-to-buffer buf)
+    (if (eq major-mode 'eshell-mode)
+        (pop-to-buffer buf)
+      (switch-to-buffer buf))
     (when command
       (+eshell-run-command command))))
 

        (format " [%s]" (substring branch 2))
      "")))

(defun +eshell-delete-window ()
  (if (one-window-p)
      (unless (doom-real-buffer-p (progn (previous-buffer) (current-buffer)))
        (switch-to-buffer (doom-fallback-buffer)))
    (delete-window)))

(defun +eshell-get-or-create-buffer ()
  (or (cl-loop for buf in (ring-elements +eshell-buffers)

;; Hooks
;;

(defun +eshell--add-buffer (buf)
  (ring-remove+insert+extend +eshell-buffers buf))

(defun +eshell--remove-buffer (buf)
  (when-let* ((idx (ring-member +eshell-buffers buf)))
    (ring-remove +eshell-buffers idx)))

;;;###autoload
(defun +eshell|init ()
  "Keep track of eshell buffers."
  (let ((buf (current-buffer)))
    (dolist (buf (ring-elements +eshell-buffers))
      (unless (buffer-live-p buf)
        (+eshell--remove-buffer buf)))
