emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sacha Chua <sacha@sachachua.com>
To: emacs-orgmode@gnu.org
Subject: Re: Cool trick on how to eval bash/zsh babel blocks in emacs
Date: Mon, 21 Apr 2014 14:45:54 -0400	[thread overview]
Message-ID: <86sip6jzbx.fsf@sachachua.com> (raw)
In-Reply-To: CAOQHXPrbTP9JVBBQU0dDd9EeCnSBEFejxddWs=geCyDvvmM3Sw@mail.gmail.com

Xebar Saram <zeltakc@gmail.com> 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

      reply	other threads:[~2014-04-21 18:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-21 18:40 Cool trick on how to eval bash/zsh babel blocks in emacs Xebar Saram
2014-04-21 18:45 ` Sacha Chua [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86sip6jzbx.fsf@sachachua.com \
    --to=sacha@sachachua.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).