emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-shell: honor the specified shell for :session
@ 2014-06-22  9:22 Achim Gratz
  2014-06-22 12:51 ` Eric Schulte
  0 siblings, 1 reply; 6+ messages in thread
From: Achim Gratz @ 2014-06-22  9:22 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 365 bytes --]


When using a shell block with a :session, the specified shell is ignored
and the original value of org-babel-sh-command (defaulting to the value
of shell-file-name as set at load-time) gets used.  The following patch
fixes this, however there are still several other problems with how
shells are invoked and how shell sessions are used that need to be
addressed.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-shell-honor-the-specified-shell-for-session.patch --]
[-- Type: text/x-patch, Size: 3291 bytes --]

From ed034803b9fd87d8f9d382303fc950d83b88711f Mon Sep 17 00:00:00 2001
From: Achim Gratz <Stromeko@Stromeko.DE>
Date: Sun, 22 Jun 2014 11:16:41 +0200
Subject: [PATCH] ob-shell: honor the specified shell for :session

* lisp/ob-shell.el: Remove defcustom `org-babel-sh-command' and
  replace with `shell-file-name' throughout.
  (org-babel-variable-assignments:sh): Make check for bash work in more
  cases.

The original code and the patched version rely on the shell being
available via PATH.  Instead the shell name should be mapped to the
appropriate executable via an alist and invoked via an absolute
filename.  For security reasons the permissible shells should probably
be taken from /etc/shells or equivalent by default.  Instead of
checking for bash, the same or another alist could provide the
information of whether or not the shell supports arrays (which indeed
were introduced by ksh originally).
---
 lisp/ob-shell.el | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 474a8f2..720af8f 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -38,13 +38,6 @@
 
 (defvar org-babel-default-header-args:sh '())
 
-(defcustom org-babel-sh-command shell-file-name
-  "Command used to invoke a shell.
-Set by default to the value of `shell-file-name'.  This will be
-passed to `shell-command-on-region'"
-  :group 'org-babel
-  :type 'string)
-
 (defcustom org-babel-sh-var-quote-fmt
   "$(cat <<'BABEL_TABLE'\n%s\nBABEL_TABLE\n)"
   "Format string used to escape variables when passed to shell scripts."
@@ -63,7 +56,7 @@ (defcustom org-babel-shell-names
      (lambda (name)
        (eval `(defun ,(intern (concat "org-babel-execute:" name)) (body params)
 		,(format "Execute a block of %s commands with Babel." name)
-		(let ((org-babel-sh-command ,name))
+		(let ((shell-file-name ,name))
 		  (org-babel-execute:shell body params)))))
      (second value))))
 
@@ -152,7 +145,7 @@ (defun org-babel-variable-assignments:sh (params)
 		     "hline"))))
     (mapcar
      (lambda (pair)
-       (if (string= org-babel-sh-command "bash")
+       (if (string-match "bash$" shell-file-name)
 	   (org-babel-variable-assignments:bash
             (car pair) (cdr pair) sep hline)
          (org-babel-variable-assignments:sh-generic
@@ -217,7 +210,7 @@ (defun org-babel-sh-evaluate (session body &optional params stdin cmdline)
                (call-process-shell-command
                 (if shebang
                     script-file
-                  (format "%s %s" org-babel-sh-command script-file))
+                  (format "%s %s" shell-file-name script-file))
                 stdin-file
                 (current-buffer) nil cmdline)
                (buffer-string))))
@@ -255,7 +248,7 @@ (defun org-babel-sh-evaluate (session body &optional params stdin cmdline)
                    (insert body))
                  (set-file-modes script-file #o755)
                  (org-babel-eval script-file ""))
-             (org-babel-eval org-babel-sh-command (org-babel-trim body)))))))
+             (org-babel-eval shell-file-name (org-babel-trim body)))))))
     (when results
       (let ((result-params (cdr (assoc :result-params params))))
         (org-babel-result-cond result-params
-- 
2.0.0


[-- Attachment #3: Type: text/plain, Size: 188 bytes --]



Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf microQ V2.22R2:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada

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

* Re: [PATCH] ob-shell: honor the specified shell for :session
  2014-06-22  9:22 [PATCH] ob-shell: honor the specified shell for :session Achim Gratz
@ 2014-06-22 12:51 ` Eric Schulte
  2014-06-23 19:09   ` Achim Gratz
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Schulte @ 2014-06-22 12:51 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-orgmode

I thought that `org-babel-sh-command' was still used if code blocks used
the keyword "shell" as the language.  If that's not the case and there
really is no more use for `org-babel-sh-command', then please go ahead
and apply this patch.

Thanks,

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D (see https://u.fsf.org/yw)

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

* Re: [PATCH] ob-shell: honor the specified shell for :session
  2014-06-22 12:51 ` Eric Schulte
@ 2014-06-23 19:09   ` Achim Gratz
  2014-06-25  8:39     ` Bastien
  0 siblings, 1 reply; 6+ messages in thread
From: Achim Gratz @ 2014-06-23 19:09 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte writes:
> I thought that `org-babel-sh-command' was still used if code blocks used
> the keyword "shell" as the language.  If that's not the case and there
> really is no more use for `org-babel-sh-command', then please go ahead
> and apply this patch.

Done on master.

In the case you mention above shell-file-name is used.  Which means that
if you change it in a running emacs session, then it will be picked up
for shell blocks (as one might reasonably expect), whereas you would
have had to change org-babel-sh-command before.  None of that was
documented anyway (and still isn't).


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf microQ V2.22R2:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada

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

* Re: [PATCH] ob-shell: honor the specified shell for :session
  2014-06-23 19:09   ` Achim Gratz
@ 2014-06-25  8:39     ` Bastien
  2014-06-30 19:10       ` Achim Gratz
  0 siblings, 1 reply; 6+ messages in thread
From: Bastien @ 2014-06-25  8:39 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-orgmode

Hi Achim,

thanks for this.

Achim Gratz <Stromeko@nexgo.de> writes:

> In the case you mention above shell-file-name is used.  Which means that
> if you change it in a running emacs session, then it will be picked up
> for shell blocks (as one might reasonably expect), whereas you would
> have had to change org-babel-sh-command before.  None of that was
> documented anyway (and still isn't).

In the perspective of Org 8.3, we need to start updating etc/ORG-NEWS.

Regardless of whether this was documented in the official manual or
not, a note in ORG-NEWS would be useful -- feel free to start editing
this file.

-- 
 Bastien

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

* Re: [PATCH] ob-shell: honor the specified shell for :session
  2014-06-25  8:39     ` Bastien
@ 2014-06-30 19:10       ` Achim Gratz
  2014-07-27 14:46         ` Bastien
  0 siblings, 1 reply; 6+ messages in thread
From: Achim Gratz @ 2014-06-30 19:10 UTC (permalink / raw)
  To: emacs-orgmode

Bastien writes:
> In the perspective of Org 8.3, we need to start updating etc/ORG-NEWS.

Done.

> Regardless of whether this was documented in the official manual or
> not, a note in ORG-NEWS would be useful -- feel free to start editing
> this file.

I've added all user-visible changes from me that will go into 8.3.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Wavetables for the Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#BlofeldUserWavetables

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

* Re: [PATCH] ob-shell: honor the specified shell for :session
  2014-06-30 19:10       ` Achim Gratz
@ 2014-07-27 14:46         ` Bastien
  0 siblings, 0 replies; 6+ messages in thread
From: Bastien @ 2014-07-27 14:46 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-orgmode

Hi Achim,

Achim Gratz <Stromeko@nexgo.de> writes:

> I've added all user-visible changes from me that will go into 8.3.

Thanks for this.  Any committer can add visible changes from anyone,
so please feel free.

Best,

-- 
 Bastien

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

end of thread, other threads:[~2014-07-28 17:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-22  9:22 [PATCH] ob-shell: honor the specified shell for :session Achim Gratz
2014-06-22 12:51 ` Eric Schulte
2014-06-23 19:09   ` Achim Gratz
2014-06-25  8:39     ` Bastien
2014-06-30 19:10       ` Achim Gratz
2014-07-27 14:46         ` Bastien

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).