From 39de4a1848d12b1be929853bf884ec04e121d9f0 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sun, 23 Jul 2023 17:38:09 +0300 Subject: [PATCH] org-babel-sh-evaluate: Fix edge case when :shebang is set and :dir is remote * lisp/ob-shell.el (org-babel-sh-evaluate): Pass remote local file name as command when executing script with :shebang. `org-babel-eval' will fail when SCRIPT-FILE is TRAMP file name. Link: https://www.reddit.com/r/orgmode/comments/14zh2yi/orgbabel_shebang_not_working_on_with_tramp_dir/ --- lisp/ob-shell.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el index 340c79abe..ae86ee4c2 100644 --- a/lisp/ob-shell.el +++ b/lisp/ob-shell.el @@ -357,7 +357,13 @@ return the value of the last statement in BODY." (when padline (insert "\n")) (insert body)) (set-file-modes script-file #o755) - (org-babel-eval script-file ""))) + (if (file-remote-p script-file) + ;; Run remote script using its local path as COMMAND. + ;; The remote execution is ensured by setting + ;; correct `default-directory'. + (let ((default-directory (file-name-directory script-file))) + (org-babel-eval (file-local-name script-file) "")) + (org-babel-eval script-file "")))) (t (org-babel-eval shell-file-name (org-trim body)))))) (when (and results value-is-exit-status) (setq results (car (reverse (split-string results "\n" t)))))