emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fix :var parameter for fish shell code blocks
@ 2023-10-13 22:42 Elias Kueny
  2023-10-15  8:35 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Elias Kueny @ 2023-10-13 22:42 UTC (permalink / raw)
  To: emacs-orgmode

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-lisp-ob-shell.el-Adapt-the-var-header-parameter-to-f.patch --]
[-- Type: text/x-patch, Size: 2147 bytes --]

From 0d8067348d033e159a460233773e442c0775a8bb Mon Sep 17 00:00:00 2001
From: Elias Kueny <elias.kueny@posteo.net>
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 fe4c7af72..9f3b614e6 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -167,6 +167,11 @@ defun org-babel--variable-assignments:sh-generic
   "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."
@@ -212,8 +217,11 @@ defun org-babel-variable-assignments:shell
        (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)
--
2.41.0

[-- Attachment #2: Type: text/plain, Size: 515 bytes --]

Hello,

I found an issue with fish shell code blocks, in that the `:var' parameter generates a command that is not syntaxically correct. Fish uses `set variable value' instead of `variable = value'. As a result, org-babel throws an error when executing the code block. This patch fixes this by adding an exception to org-babel-variable-assignments:shell on the model of what it already does for bash.

Example of code block triggering the error:
#+begin_src fish :var test
echo $test
#+end_src

Best regards,
Elias

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix :var parameter for fish shell code blocks
  2023-10-13 22:42 [PATCH] Fix :var parameter for fish shell code blocks Elias Kueny
@ 2023-10-15  8:35 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2023-10-15  8:35 UTC (permalink / raw)
  To: Elias Kueny; +Cc: emacs-orgmode

Elias Kueny <elias.kueny@posteo.net> writes:

> I found an issue with fish shell code blocks, in that the `:var' parameter generates a command that is not syntaxically correct. Fish uses `set variable value' instead of `variable = value'. As a result, org-babel throws an error when executing the code block. This patch fixes this by adding an exception to org-babel-variable-assignments:shell on the model of what it already does for bash.

Thanks for the patch!
Applied, onto bugfix.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c42cdcda4

You are now listed as an Org contributor:
https://git.sr.ht/~bzg/worg/commit/fdc3c55f

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-15  8:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-13 22:42 [PATCH] Fix :var parameter for fish shell code blocks Elias Kueny
2023-10-15  8:35 ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).