From 7a6c0e35415c4a173d101336029262f3a09abb91 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 13 Dec 2013 09:52:05 -0700 Subject: [PATCH 1/4] multiple code block types for multiple shells * lisp/ob-sh.el (org-babel-sh-command): Now set from `shell-file-name'. (org-babel-shell-names): List of specific shells known to Org mode shell code blocks. (org-babel-execute:shell): New generic shell execution function. --- lisp/ob-sh.el | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lisp/ob-sh.el b/lisp/ob-sh.el index 4984ff9..a115f38 100644 --- a/lisp/ob-sh.el +++ b/lisp/ob-sh.el @@ -38,9 +38,12 @@ (defvar org-babel-default-header-args:sh '()) -(defvar org-babel-sh-command "sh" +(defcustom org-babel-sh-command shell-file-name "Command used to invoke a shell. -This will be passed to `shell-command-on-region'") +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)" @@ -48,7 +51,22 @@ This will be passed to `shell-command-on-region'") :group 'org-babel :type 'string) -(defun org-babel-execute:sh (body params) +(defcustom org-babel-shell-names '("sh" "bash" "csh" "ash" "dash") + "List of names of shell supported by babel shell code blocks." + :group 'org-babel + :type 'string + :initialize + (lambda (symbol value) + (set-default symbol (second value)) + (mapc + (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)) + (org-babel-execute:shell body params))))) + (second value)))) + +(defun org-babel-execute:shell (body params) "Execute a block of Shell commands with Babel. This function is called by `org-babel-execute-src-block'." (let* ((session (org-babel-sh-initiate-session -- 1.8.5.1