emacsorg-babel

Remove the command line prompt from results of the babel's shell code


Upon running commands on org's babel source code

#+BEGIN_SRC shell :session hugo :results output
hugo new posts/my_first_post.md
#+END_SRC

#+RESULTS:
: /home/me/Documents/quickstart/content/posts/my_first_post.md created
: (base) [01;32mme@alpha[00m:[01;34m~/Documents/quickstart[00m:

There's a prompt suffix appended : (base) [01;32mme@alpha[00m:[01;34m~/Documents/quickstart[00m:

Other examples

#+BEGIN_SRC shell :session hugo  :results output
cat ./content/posts/my_first_post.md 
#+END_SRC

#+RESULTS:
: ---
: title: "My_first_post"
: date: 2019-09-06T13:46:46+08:00
: draft: true
: ---
: 
: (base) [01;32mme@alpha[00m:[01;34m~/Documents/quickstart[00m:

How could remove the suffix by configure the babel' header arguments.


Solution

  • The simplest might be just to set your prompt, PS1 in your initial code block. Org-babel does attempt to clean the prompt with org-babel-sh-strip-weird-long-prompt, but it doesn't appear easily customizable. So, you could just use

    #+BEGIN_SRC shell :session hugo :results output
    PS1="> "
    echo
    #+END_SRC
    

    Since you're using :session you should only need it in your initial block.

    Note: it looks like this should only be an issue when using a session, since the shell isn't run through comint otherwise