From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sacha Chua Subject: Re: Cool trick on how to eval bash/zsh babel blocks in emacs Date: Mon, 21 Apr 2014 14:45:54 -0400 Message-ID: <86sip6jzbx.fsf@sachachua.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcJEI-0004Ea-1o for emacs-orgmode@gnu.org; Mon, 21 Apr 2014 14:46:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WcJE9-0002R6-Eb for emacs-orgmode@gnu.org; Mon, 21 Apr 2014 14:46:10 -0400 Received: from plane.gmane.org ([80.91.229.3]:59935) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WcJE9-0002R1-8y for emacs-orgmode@gnu.org; Mon, 21 Apr 2014 14:46:01 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WcJE6-0003Og-V7 for emacs-orgmode@gnu.org; Mon, 21 Apr 2014 20:45:58 +0200 Received: from 184.175.19.126 ([184.175.19.126]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Apr 2014 20:45:58 +0200 Received: from sacha by 184.175.19.126 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 21 Apr 2014 20:45:58 +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 Xebar Saram writes: Hello, all! > Thanks to the always amazing sacha chua here is a neat way to evaluate/run > bash/zsh command line commands inside the emacs term. i find this very > useful for collecting multiple bash snippets and quickly running them > here is the code > #+begin_src emacs-lisp > (defadvice org-babel-execute:sh (around sacha activate) > (if (assoc-default :term (ad-get-arg 1) nil) > (let ((buffer (make-term "babel" "/bin/zsh"))) > (with-current-buffer buffer > (insert (org-babel-expand-body:generic > body params (org-babel-variable-assignments:sh params))) > (term-send-input)) > (pop-to-buffer buffer)) > ad-do-it)) > #+end_src To use this: #+begin_src sh :term t ls -l echo "Hello world" #+end_src Probably good to replace the "/bin/zsh" call with (or explicit-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh")) So the original context of this was that zeltak wanted a way to run sh babel blocks in a separate term so that he could interact with the results of the process instead of having the output go into a results block. I'm not sure if there's already a proper way to do this (didn't seem like it from org-babel-execute:sh), so I added a custom :term parameter and advised the execution of org-babel-execute.sh. Seems to work. Of course, proper implementation would get rid of the advice, and also maybe use :results term or something like that. Anyway, before we dig into implementation details and documentation updates: Is interacting with babel output something that might be interesting to include? If so, how should it behave? Sacha