0

To increase modularisation of my emacs code blocks I'm attempting to factor out common functionality into separate function blocks. I'm running into difficulties with chaining :post calls, and using :stdin for the filter blocks. I've composed this minimal example showing the workaround I used for stdin (and an unsuccessful attempt), and where I'd like to "chain" post-processing functions at will. Executing the first block results in a colored rendering of ip route to HTML-Code.

#+Title: My Tower of Babel
* Functions
  These functions need =grc= and =ansi2html= installed.

** Data Generation
*** IP-Routes
#+NAME: IP-Routes
#+HEADER: :post GRC(cfg="ip", grcraw=*this*)
#+BEGIN_SRC shell :wrap HTML :results verbatim
ip route
#+END_SRC


** Post-Processing
*** ANSI2HTML
#+NAME: ANSI-TO-HTML
#+BEGIN_SRC shell :var ansiraw="[0m[44mdata[0m" :results verbatim
echo -n "$ansiraw" | ansi2html -n -w
#+END_SRC

*** GRC
#+NAME: GRC
#+HEADER: :var cfg="df" :var grcraw="RAWDATA" :post ANSI-TO-HTML(ansiraw=*this*)
#+BEGIN_SRC shell :results verbatim
echo -n "$grcraw" | grcat conf.$cfg
#+END_SRC

*** columnator
#+NAME: COLUMN
#+HEADER: :var columnraw="a b c\n"
#+HEADER: :prologue "echo \"$columnraw\" | "
#+BEGIN_SRC shell
column -t
#+END_SRC
  • In the code above I use an ugly temporary variable to hold/transfer the contents of STDIN. How can I do without that? I attempted to use the :prologue to get around that to no avail. Ideally, I'd like *this* from the top block to just "flow" through.

  • With the above code I cannot use GRC without rendering to HTML.

  • Now to add COLUMN as additional "one-off" filter to IP-Routes I tried:

    • Adding another :post statement before GRC
    • Nesting them with various syntax attempts

So, in short, I'm misunderstanding something about chaining shell code blocks as a compose-able pipeline of post-processing filters for STDIN/STDOUT.

  • Not really a minimal example if two external programs are needed, but the Q is about org-babel. You might get more answers if this were a better minimal Q. – mankoff Jan 31 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.