1

When I run a shell command in Org I sometimes get back weird control characters:

#+begin_src sh :results output :session test
guix pull
#+end_src

#+RESULTS:
: 
: Updating channel 'guix' from Git repository at 'https://git.savannah.gnu.org/git/guix.git'...
: Building from this channel:
:   guix      https://git.savannah.gnu.org/git/guix.git 258a27e
: Computing Guix derivation for 'x86_64-linux'...  ^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\^H|^H/^H-^H\
: nothing to be done

It's not just ^H, but many others. I can replace them if I have them present. However, I can't store them in a regex within a clean-up function because it's not clear how to encode the file it's saved in.

Answers to similar questions have suggested to check locale. I would think this should be okay:

#+begin_src sh :results output :session test
export | grep LANG
#+end_src

#+RESULTS:
: export GDM_LANG="en_US.utf8"
: export LANG="en_US.utf8"

Others have suggested changing PS1 in .bashrc. These made no difference. It seems the shell used by Org is already stripped down:

#+begin_src sh :results output :session test
echo $PS1
#+end_src

#+RESULTS:
: 
: \s-\v\$

Still more have suggested bracketed paste mode may be a factor. It may be, but definitely not for the guix pull above. As far as I understand, bracketed paste mode is only for ESC [ 2 0 0 ~ , and ESC [ 2 0 1 ~ .. I have not seen these or, at the very least can't reproduce them.

I'm at a loss for how to clean up these control characters or, better yet, not produce them in the first place. Any advice?

Lorem Ipsum
  • 4,327
  • 2
  • 14
  • 35
  • Do `guix pull > guix.out 2>&1` and check the output file with `M-x find-file-literally`. If that includes the weird characters, then you have to filter the output of `guix pull`. Maybe there is an option to turn the weird characters off. The `^H-` suggests that it's trying to produce an overstrike effect. – NickD Oct 17 '21 at 12:59

1 Answers1

1

guix is making a spinner by printing a character, backspacing over it, and printing something else. Programs are only supposed to do these things if they have reason to believe that their output is going to a terminal. Since org-mode is not a terminal, guix shouldn’t be doing this. It might be a bug you should report to them at https://issues.guix.gnu.org/, but it could just be that it thinks that it is in a terminal.

What is TERM getting set to in the subprocess?

#+begin_src sh :results output
echo $TERM
#+end_src

#+RESULTS:
: dumb

If it is anything other than “dumb”, then you should check your shell startup files to see if you’re explicitly setting it to something else. This is quite common, but always a mistake. You should allow your terminal to set it for you, and then leave it alone.

db48x
  • 15,741
  • 1
  • 19
  • 23