From c42cdcda4789122c3c8ed477365b9369bdf0af87 Mon Sep 17 00:00:00 2001 From: Elias Kueny Date: Sat, 14 Oct 2023 00:20:55 +0200 Subject: [PATCH] lisp/ob-shell.el: Adapt the `:var' header parameter to fish * ob-shell.el (org-babel-variable-assignments:shell): allow the `:var' keyword on fish code blocks to work with fish variables. The fish shell uses the syntax `set variable value' instead of `value=value' to set a shell variable. This caused org-babel to return an syntax error when attempting to execute a fish code block with a `:var' parameter. This change adds a helper function to use the correct format. TINYCHANGE --- lisp/ob-shell.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el index 2c30a2605..87e38e414 100644 --- a/lisp/ob-shell.el +++ b/lisp/ob-shell.el @@ -166,6 +166,11 @@ This function is called by `org-babel-execute-src-block'." "Return a list of statements declaring the values as a generic variable." (format "%s=%s" varname (org-babel-sh-var-to-sh values sep hline))) +(defun org-babel--variable-assignments:fish + (varname values &optional sep hline) + "Return a list of statements declaring the values as a fish variable." + (format "set %s %s" varname (org-babel-sh-var-to-sh values sep hline))) + (defun org-babel--variable-assignments:bash_array (varname values &optional sep hline) "Return a list of statements declaring the values as a bash array." @@ -211,8 +216,11 @@ This function is called by `org-babel-execute-src-block'." (if (string-suffix-p "bash" shell-file-name) (org-babel--variable-assignments:bash (car pair) (cdr pair) sep hline) - (org-babel--variable-assignments:sh-generic - (car pair) (cdr pair) sep hline))) + (if (string-suffix-p "fish" shell-file-name) + (org-babel--variable-assignments:fish + (car pair) (cdr pair) sep hline) + (org-babel--variable-assignments:sh-generic + (car pair) (cdr pair) sep hline)))) (org-babel--get-vars params)))) (defun org-babel-sh-var-to-sh (var &optional sep hline)