shell: Fix helm-ff's M-e when point is not on prompt.

master
Pierre Neidhardt 2020-06-08 10:37:52 +02:00
parent 218520fd7a
commit e81d8814d7
1 changed files with 17 additions and 9 deletions

View File

@ -1,10 +1,10 @@
(defun ambrevar/helm-ff--shell-interactive-buffer-p (buffer)
(with-current-buffer buffer
;; (and (save-excursion
;; (goto-char (point-min))
;; (eshell-next-prompt 1)
;; (null (eql (point) (point-min)))))
(eq major-mode 'shell-mode)))
(and (eq major-mode 'shell-mode)
(save-excursion
(goto-char (point-min))
(comint-next-prompt 1)
(null (eql (point) (point-min)))))))
(defun ambrevar/helm-ff-switch-to-shell (_candidate)
"Like `helm-ff-switch-to-eshell' but for `M-x shell'.
@ -14,10 +14,17 @@ prefix arg provided and more than one shell buffer exists, provide
completions on those buffers. If only one shell buffer exists,
switch to this one, if no shell buffer exists or if the numeric
prefix arg shell buffer doesn't exists, create it and switch to it."
(let ((cd-shell (lambda ()
(comint-delete-input)
(insert (format "cd %s" (shell-quote-argument helm-ff-default-directory)))
(comint-send-input)))
(let ((cd-shell
(lambda ()
(goto-char (point-max))
(comint-delete-input)
(insert (format "cd %s"
(shell-quote-argument
(if (tramp-tramp-file-p helm-ff-default-directory)
(tramp-file-name-localname
(tramp-dissect-file-name helm-ff-default-directory))
helm-ff-default-directory))))
(comint-send-input)))
(bufs (cl-loop for b in (mapcar 'buffer-name (buffer-list))
when (ambrevar/helm-ff--shell-interactive-buffer-p b)
collect b)))
@ -28,6 +35,7 @@ prefix arg shell buffer doesn't exists, create it and switch to it."
(car bufs)))
(switch-to-buffer it)
(shell))
;; TODO: Can we check if a process is currently running within the running shell?
(funcall cd-shell)))
(advice-add 'helm-ff-switch-to-eshell :override 'ambrevar/helm-ff-switch-to-shell)