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