Function: org-babel-execute:eshell

org-babel-execute:eshell is a byte-compiled function defined in ob-eshell.el.gz.

Signature

(org-babel-execute:eshell BODY PARAMS)

Documentation

Execute a block of Eshell code BODY with PARAMS.

This function is called by org-babel-execute-src-block.

The BODY can be any code which allowed executed in Eshell. Eshell allow to execute normal shell command and Elisp code. More details please reference Eshell Info.

The PARAMS are variables assignments.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-eshell.el.gz
(defun org-babel-execute:eshell (body params)
  "Execute a block of Eshell code BODY with PARAMS.
This function is called by `org-babel-execute-src-block'.

The BODY can be any code which allowed executed in Eshell.
Eshell allow to execute normal shell command and Elisp code.
More details please reference Eshell Info.

The PARAMS are variables assignments."
  (let* ((session (org-babel-eshell-initiate-session
		   (cdr (assq :session params))))
	 (full-body (org-babel-expand-body:generic
		     body params (org-babel-variable-assignments:eshell params))))
    (if session
	(progn
	  (with-current-buffer session
	    (dolist (line (split-string full-body "\n"))
	      (goto-char eshell-last-output-end)
	      (insert line)
	      (eshell-send-input))
	    ;; get output of last input
	    ;; TODO: collect all output instead of last command's output.
	    (goto-char eshell-last-input-end)
	    (buffer-substring-no-properties (point) eshell-last-output-start)))
      (with-temp-buffer
	(eshell-command full-body t)
	(buffer-string)))))