emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Achim Gratz <Stromeko@nexgo.de>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ob-shell: honor the specified shell for :session
Date: Sun, 22 Jun 2014 11:22:44 +0200	[thread overview]
Message-ID: <87r42h8fiz.fsf@Rainer.invalid> (raw)

[-- 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

             reply	other threads:[~2014-06-22  9:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-22  9:22 Achim Gratz [this message]
2014-06-22 12:51 ` [PATCH] ob-shell: honor the specified shell for :session 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r42h8fiz.fsf@Rainer.invalid \
    --to=stromeko@nexgo.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).