emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH] ob-shell: honor the specified shell for :session


From: Achim Gratz
Subject: [O] [PATCH] ob-shell: honor the specified shell for :session
Date: Sun, 22 Jun 2014 11:22:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.91 (gnu/linux)

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.

>From ed034803b9fd87d8f9d382303fc950d83b88711f Mon Sep 17 00:00:00 2001
From: Achim Gratz <address@hidden>
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


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 via email to

[Prev in Thread] Current Thread [Next in Thread]