tools/eshell: add command argument to eshell open commands

This commit is contained in:
Henrik Lissner 2017-09-27 14:48:05 +02:00
parent 74eaed414e
commit 838615eb0c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -7,26 +7,33 @@
"The name to use for custom eshell buffers. This only affects `+eshell/open', "The name to use for custom eshell buffers. This only affects `+eshell/open',
`+eshell/open-popup' and `+eshell/open-workspace'.") `+eshell/open-popup' and `+eshell/open-workspace'.")
;; --- Commands ---------------------------
;;;###autoload ;;;###autoload
(defun +eshell/open () (defun +eshell/open (&optional command)
"Open eshell in the current buffer." "Open eshell in the current buffer."
(interactive) (interactive)
(let ((buf (generate-new-buffer +eshell-buffer-name))) (let ((buf (generate-new-buffer +eshell-buffer-name)))
(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)
(when command
(+eshell-run-command command))))
;;;###autoload ;;;###autoload
(defun +eshell/open-popup () (defun +eshell/open-popup (&optional command)
"Open eshell in a popup window." "Open eshell in a popup window."
(interactive) (interactive)
(let ((buf (get-buffer-create +eshell-buffer-name))) (let ((buf (get-buffer-create +eshell-buffer-name)))
(with-current-buffer buf (with-current-buffer buf
(unless (eq major-mode 'eshell-mode) (eshell-mode))) (unless (eq major-mode 'eshell-mode) (eshell-mode)))
(doom-popup-buffer buf '(:autokill t) t))) (doom-popup-buffer buf '(:autokill t) t)
(when command
(+eshell-run-command command))))
;;;###autoload ;;;###autoload
(defun +eshell/open-workspace () (defun +eshell/open-workspace (&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)
@ -38,7 +45,19 @@ module to be loaded."
(doom-visible-windows))) (doom-visible-windows)))
(select-window (get-buffer-window buf)) (select-window (get-buffer-window buf))
(+eshell/open)) (+eshell/open))
(doom/workspace-display)) (doom/workspace-display)
(when command
(+eshell-run-command command)))
(defun +eshell-run-command (command)
(unless (cl-remove-if-not #'buffer-live-p +eshell-buffers)
(user-error "No living eshell buffers available"))
(with-current-buffer (car +eshell-buffers)
(goto-char eshell-last-output-end)
(when (bound-and-true-p evil-mode)
(call-interactively #'evil-append-line))
(insert command)
(eshell-send-input nil t)))
;; --- Hooks ------------------------------ ;; --- Hooks ------------------------------