Browse Source

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.
Eric Schulte 11 years ago
parent
commit
7a6c0e3541
1 changed files with 21 additions and 3 deletions
  1. 21 3
      lisp/ob-sh.el

+ 21 - 3
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