Fix #2014: +shell/here doesn't execute COMMAND

This commit is contained in:
Henrik Lissner 2020-01-01 22:47:59 -05:00
parent 8f5977d9b8
commit f0abb3264c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -41,6 +41,18 @@ prompt."
(when (memq (process-status process) '(exit stop)) (when (memq (process-status process) '(exit stop))
(kill-buffer (process-buffer process)))) (kill-buffer (process-buffer process))))
(defun +shell--send-input (buffer input &optional no-newline)
(when input
(with-current-buffer buffer
(unless (number-or-marker-p (cdr comint-last-prompt))
(message "Waiting for shell to start up...")
(while (not (number-or-marker-p (cdr comint-last-prompt)))
(sleep-for 0.1)))
(goto-char (cdr comint-last-prompt))
(delete-region (cdr comint-last-prompt) (point-max))
(insert input)
(comint-send-input no-newline))))
;;;###autoload ;;;###autoload
(defun +shell/toggle (&optional command) (defun +shell/toggle (&optional command)
@ -69,12 +81,11 @@ If popup is focused, kill it."
(with-current-buffer (pop-to-buffer buffer) (with-current-buffer (pop-to-buffer buffer)
(if (not (eq major-mode 'shell-mode)) (if (not (eq major-mode 'shell-mode))
(shell buffer) (shell buffer)
(run-mode-hooks 'shell-mode-hook) (cd dir)
(cd dir)) (run-mode-hooks 'shell-mode-hook))))
(let ((process (get-buffer-process (current-buffer)))) (when-let (process (get-buffer-process buffer))
(set-process-sentinel process #'+shell--sentinel) (set-process-sentinel process #'+shell--sentinel)
(when command (+shell--send-input buffer command))))
(comint-send-string process command)))))))
;;;###autoload ;;;###autoload
(defun +shell/here (&optional command) (defun +shell/here (&optional command)
@ -85,14 +96,12 @@ If already in a shell buffer, clear it and cd into the current directory."
(let ((buffer (+shell-unused-buffer)) (let ((buffer (+shell-unused-buffer))
(dir default-directory)) (dir default-directory))
(with-current-buffer (switch-to-buffer buffer) (with-current-buffer (switch-to-buffer buffer)
(if (not (eq major-mode 'shell-mode)) (if (eq major-mode 'shell-mode)
(shell buffer) (+shell--send-input buffer (format "cd %S" dir))
(erase-buffer) (shell buffer))
(cd dir)) (let ((process (get-buffer-process buffer)))
(let ((process (get-buffer-process (current-buffer))))
(set-process-sentinel process #'+shell--sentinel) (set-process-sentinel process #'+shell--sentinel)
(when command (+shell--send-input buffer command)))
(comint-send-string process command))))
buffer)) buffer))