From mboxrd@z Thu Jan 1 00:00:00 1970 From: Achim Gratz Subject: [PATCH] ob-shell: honor the specified shell for :session Date: Sun, 22 Jun 2014 11:22:44 +0200 Message-ID: <87r42h8fiz.fsf@Rainer.invalid> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WydzO-0007bm-2G for emacs-orgmode@gnu.org; Sun, 22 Jun 2014 05:23:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WydzI-0001Zc-7D for emacs-orgmode@gnu.org; Sun, 22 Jun 2014 05:23:06 -0400 Received: from plane.gmane.org ([80.91.229.3]:59633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WydzI-0001ZY-0t for emacs-orgmode@gnu.org; Sun, 22 Jun 2014 05:23:00 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WydzH-0001b9-5r for emacs-orgmode@gnu.org; Sun, 22 Jun 2014 11:22:59 +0200 Received: from pd9eb0993.dip0.t-ipconnect.de ([217.235.9.147]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 22 Jun 2014 11:22:59 +0200 Received: from Stromeko by pd9eb0993.dip0.t-ipconnect.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 22 Jun 2014 11:22:59 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-shell-honor-the-specified-shell-for-session.patch >From ed034803b9fd87d8f9d382303fc950d83b88711f Mon Sep 17 00:00:00 2001 From: Achim Gratz 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 --=-=-= Content-Type: text/plain 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 --=-=-=--