`org-export-to-html` does not export ANSI colors - org-mode

The Issue
after running org-export-to-html on the following code:
#+BEGIN_SRC shell :exports both :results output
echo -e "\e[0;31mOUTPUT\e[0m"
#+END_SRC
OUTPUT is exported in black color
Desired output
OUTPUT being exported in red color
Proposed solution
The following code exports the output to html using (aha)
#+BEGIN_SRC shell :exports both :results output html
echo -e "\e[0;31mOUTPUT\e[0m" | aha
#+END_SRC
The issue with the proposed solution
The initial command is just echo -e "\e[0;31mOUTPUT\e[0m" not echo -e "\e[0;31mOUTPUT\e[0m" | aha

Related

how to make org-babel-tangle to take account of :dir property?

I want org babel to take account of the dir header property when i use org-babel-tangle.
E.g.
#+begin_src bash :dir ~/blubb
echo $PWD
#+end_src
or even
#+begin_src bash :dir /ssh:someone#somewhere|sudo:anotherone#somewhere:somedir
echo $(hostname) $USER $PWD
#+end_src
When I do org-babel-tangle it creates a bash file with just the echo statement. I would like it to do a dir change, or wrap it in an ssh statement for the second example. (Same issue when I do org-export: the dir information is lost).
Has anybody found a solution for that?

org-babel shell always binds to "fish"

I have the excellent fish shell set as the default shell on my main laptop. For portability reasons (and editability reasons, as editing fish shell source blocks is buggy and slow) I'd still like to sometimes use sh or bash in my org-mode source blocks. It seems that org always resolves to fish, no matter what I try:
#+BEGIN_SRC sh
echo $SHELL
#+END_SRC
#+RESULTS:
: /usr/bin/fish
#+BEGIN_SRC bash
echo $SHELL
#+END_SRC
#+RESULTS:
: /usr/bin/fish
#+BEGIN_SRC fish
echo $SHELL
#+END_SRC
#+RESULTS:
: /usr/bin/fish
#+BEGIN_SRC shell
echo $SHELL
#+END_SRC
#+RESULTS:
: /usr/bin/fish
org-babel-shell-names is set to ("sh" "bash" "zsh" "fish" "csh" "ash" "dash" "ksh" "mksh" "posh"). How do I debug this? Or is there any way to set the shell to bash globally for org-babel? I'm using emacs 26.3 with the spacemacs configuration at commit 5fcd84d84 and latest org-mode.
I think you'll find that the SHELL environment variable isn't what you think it is.
Try echoing $0 instead -- or running any built-in shell command which will give shell-specific output (bash has a help command, for example).

Preserve color running an external command via exec

Is it possible to run an external command in a perl script and preserve the color?
As a simple example, how would I run ls from a perl script and get colored output:
#! /usr/bin/perl
exec "ls";
When I run this, the output is all white, but I would like to preserve the colors, in this example for the directories and executables, etc...
It appears that ls doesn't automatically turn on colours in a subshell.
$ echo `ls`
# Output is uncoloured
We can work around that by using the --color command-line option.
$ echo `ls --color`
# Output is coloured
You can use a similar trick in a subshell that is invoked from Perl.
$ perl -e 'system "ls"'
# Output is uncoloured
$ perl -e 'system "ls --color"'
# Output is coloured.

Org-Mode: Image get corrupted in result

I am using Emacs Org-Mode and I am trying to fetch a picture from the web using wget and display it as an inline image in a code block result. So, I write the following block of code:
#+BEGIN_SRC bash :results file :file ~/image.jpg
url='https://gist.githubusercontent.com/brettlangdon/85942af486eb79118467/raw/2a7409cd3c26a90b2e82bdc40dc7db18b92b3517/06b3FMA.jpg'
wget "$url" -O ~/image.jpg
#+END_SRC
#+RESULTS:
[[file:~/image.jpg]]
However, the image is not display and get corrupted. In console I get:
Premature end of JPEG file
#+BEGIN_SRC bash
url='https://gist.githubusercontent.com/brettlangdon/85942af486eb79118467/raw/2a7409cd3c26a90b2e82bdc40dc7db18b92b3517/06b3FMA.jpg'
wget "$url" -O ~/image.jpg
#+END_SRC
Executes script, downloading the specified URL to ~/image.jpg
#+BEGIN_SRC bash :results file :file ~/image.jpg
url='https://gist.githubusercontent.com/brettlangdon/85942af486eb79118467/raw/2a7409cd3c26a90b2e82bdc40dc7db18b92b3517/06b3FMA.jpg'
wget "$url" -O ~/image.jpg
#+END_SRC
Executes script, downloading the specified URL to ~/image.jpg, and then writes the standard output from the shell command to ~/image.jpg (which I expect leaves you with an empty file, as wget writes information to stderr).
So you can either use the first approach and include your image link independently of the code block; or if you want the downloaded image data to be captured in the :results you need to tell wget to write to stdout.
#+BEGIN_SRC bash :results file :file ~/image.jpg
url='https://gist.githubusercontent.com/brettlangdon/85942af486eb79118467/raw/2a7409cd3c26a90b2e82bdc40dc7db18b92b3517/06b3FMA.jpg'
wget "$url" -O -
#+END_SRC

pipe both, stdout and stderr in the fish shell

I know this has been an issue for a while and I found a lot of discussion about it, however I didn't get which would be finally a way to get it done: pipe both, stdout and stderr. In bash, this would be simply:
cmd 2>&1 | cmd2
That syntax works in fish too. A demo:
$ function cmd1
echo "this is stdout"
echo "this is stderr" >&2
end
$ function cmd2
rev
end
$ cmd1 | cmd2
this is stderr
tuodts si siht
$ cmd1 &| cmd2
rredts si siht
tuodts si siht
Docs: https://fishshell.com/docs/current/language.html#redirects
There's also a handy shortcut, per these docs
&>
Here's the relevant quote (emphasis and white space, mine):
As a convenience, the redirection &> can be used to direct both stdout
and stderr to the same destination. For example:
echo hello &> all_output.txt
redirects both stdout and stderr to the file
all_output.txt. This is equivalent to echo hello > all_output.txt 2>&1.