1

When running M-x shell I get strange additional characters.

It looks like this,

enter image description here

I should look similar to how it does in the terminal,

enter image description here

I am very new to Emacs. Hopefully there is a simple fix.

I am running Fedora 25 and GNU Emacs 25.1.1

Dan
  • 32,584
  • 6
  • 98
  • 168
Shane G
  • 111
  • 2

1 Answers1

1

The problem is in your shell configuration. It's sending escape sequences to color parts of the prompt, to set the terminal sequence, etc. But the terminal of M-x shell is a very basic one that doesn't understand these escape sequences. You need to turn off all these features.

The basic way to detect the terminal capabilities is to query the TERM variable. Under M-x shell, its value is dumb. Turn off all prompt formatting and other similar configuration when $TERM is dumb.

For example, if your shell is bash, use something like in your .bashrc:

if [[ "$TERM" == "dumb" ]]; then
  # No terminal escape sequences, only prompt escapes
  PS1='\u at \h in \w\n\$ '
else
  # Assuming a rich terminal, using terminal escape sequences
  PS1='\e]2;\w\a\e]1;\W\a\u at \h in \w\n\$ '
fi