Open eshell in project root by default

If passed the universal arg (SPC u SPC o e) or (C-u M-x +eshell/open),
it will open in the current directory.
This commit is contained in:
Henrik Lissner 2018-06-18 14:42:42 +02:00
parent 08f01edafd
commit c8aba6f552
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -72,10 +72,11 @@
;; ;;
;;;###autoload ;;;###autoload
(defun +eshell/open (&optional command) (defun +eshell/open (arg &optional command)
"Open eshell in the current buffer." "Open eshell in the current buffer."
(interactive) (interactive "P")
(let ((buf (+eshell--buffer (eq major-mode 'eshell-mode)))) (let* ((default-directory (if arg default-directory (doom-project-root)))
(buf (+eshell--buffer (eq major-mode 'eshell-mode))))
(with-current-buffer buf (with-current-buffer buf
(unless (eq major-mode 'eshell-mode) (eshell-mode))) (unless (eq major-mode 'eshell-mode) (eshell-mode)))
(switch-to-buffer buf) (switch-to-buffer buf)
@ -84,10 +85,11 @@
(+eshell-run-command command)))) (+eshell-run-command command))))
;;;###autoload ;;;###autoload
(defun +eshell/open-popup (&optional command) (defun +eshell/open-popup (arg &optional command)
"Open eshell in a popup window." "Open eshell in a popup window."
(interactive) (interactive "P")
(let ((buf (+eshell--buffer))) (let* ((default-directory (if arg default-directory (doom-project-root)))
(buf (+eshell--buffer)))
(with-current-buffer buf (with-current-buffer buf
(unless (eq major-mode 'eshell-mode) (eshell-mode))) (unless (eq major-mode 'eshell-mode) (eshell-mode)))
(pop-to-buffer buf) (pop-to-buffer buf)
@ -96,23 +98,24 @@
(+eshell-run-command command)))) (+eshell-run-command command))))
;;;###autoload ;;;###autoload
(defun +eshell/open-workspace (&optional command) (defun +eshell/open-workspace (arg &optional command)
"Open eshell in a separate workspace. Requires the (:feature workspaces) "Open eshell in a separate workspace. Requires the (:feature workspaces)
module to be loaded." module to be loaded."
(interactive) (interactive "P")
(unless (featurep! :feature workspaces) (let ((default-directory (if arg default-directory (doom-project-root))))
(user-error ":feature workspaces is required, but disabled")) (unless (featurep! :feature workspaces)
(unless (+workspace-get "eshell" t) (user-error ":feature workspaces is required, but disabled"))
(+workspace/new "eshell")) (unless (+workspace-get "eshell" t)
(if-let* ((buf (cl-find-if (lambda (buf) (eq 'eshell-mode (buffer-local-value 'major-mode buf))) (+workspace/new "eshell"))
(doom-visible-windows) (if-let* ((buf (cl-find-if (lambda (buf) (eq 'eshell-mode (buffer-local-value 'major-mode buf)))
:key #'window-buffer))) (doom-visible-windows)
(select-window (get-buffer-window buf)) :key #'window-buffer)))
(+eshell/open)) (select-window (get-buffer-window buf))
(when command (+eshell/open arg))
(+eshell-run-command command)) (when command
(+eshell--set-window (selected-window) t) (+eshell-run-command command))
(doom/workspace-display)) (+eshell--set-window (selected-window) t)
(doom/workspace-display)))
(defun +eshell-run-command (command) (defun +eshell-run-command (command)
(unless (cl-remove-if-not #'buffer-live-p +eshell-buffers) (unless (cl-remove-if-not #'buffer-live-p +eshell-buffers)