diff --git a/lisp/simple.el b/lisp/simple.el index e51bc132a6..1c3c1f8a9b 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3844,7 +3844,42 @@ shell-command-to-string (with-output-to-string (with-current-buffer standard-output - (process-file shell-file-name nil t nil shell-command-switch command)))) + (when (file-remote-p default-directory) + ;; Borrow from shell in shell.el + ;; Apply connection-local variables. + (hack-connection-local-variables-apply + `(:application tramp + :protocol ,(file-remote-p default-directory 'method) + :user ,(file-remote-p default-directory 'user) + :machine ,(file-remote-p default-directory 'host))) + + ;; On remote hosts, the local `shell-file-name' might be useless. + (if (and (called-interactively-p 'any) + (null explicit-shell-file-name) + (null (getenv "ESHELL"))) + (set (make-local-variable 'explicit-shell-file-name) + (file-local-name + (expand-file-name + (read-file-name + "Remote shell path: " default-directory shell-file-name + t shell-file-name)))))) + + (unless (comint-check-proc standard-output) + (let* ((prog (or explicit-shell-file-name + (getenv "ESHELL") shell-file-name)) + ;; we can't use "-i" + ;; (name (file-name-nondirectory prog)) + ;; (xargs-name (intern-soft (concat "explicit-" name "-args"))) + ) + (process-file prog nil t nil + ;; here we can't use "-i" + ;; (if (and xargs-name (boundp xargs-name)) + ;; (mapconcat 'identity (symbol-value xargs-name) " ") + ;; shell-command-switch) + shell-command-switch + command) + )) + ))) (defun process-file (program &optional infile buffer display &rest args) "Process files synchronously in a separate process.