5

I have shell-mode set up to work with ANSI colors. In older versions of Emacs, this extended to the prompt but now it doesn't and the prompt remains uncolored.

PS1 is set with ANSI color codes which work when it's printed out but don't work in the actual prompt itself:

PS1 set with color.

I tried following the advice from an old StackOverflow answer and setting the comint-highlight-prompt face to not inherit:

(set-face-attribute 'comint-highlight-prompt nil
                    :inherit nil)

This made the prompt the same color as normal text, still ignoring ANSI codes:

enter image description here

It seems like versions of comint.el had a custom-set variable comint-highlight-prompt which could be set to nil, but the variable doesn't seem to exist on my version of Emacs. (Actually, I'm not sure exactly where that file came from, but I found it on a Google search :).)

Tikhon Jelvis
  • 6,152
  • 2
  • 27
  • 40

2 Answers2

1

After a bit more searching, I found that this is a known bug (bug#20084). It looks like a fix has been pushed to master and should be available in Emacs 25:

I've now pushed my patch (which, I hope, is a proper fix) to master.

This change is only in the master branch and has not been back-ported to emacs-24. So, presumably, 25.1 will be the first release where this works.

Tikhon Jelvis
  • 6,152
  • 2
  • 27
  • 40
0

There is a trick:

init.el file

(set-face-attribute 'comint-highlight-prompt nil
                    :inherit nil)

and the trick:

init_bash.sh file

PS1="\[\e[00;32m\]\u\[\e[00m\]@\[\e[00;36m\]\h\[\e[00m\]:\[\e[00;34m\]\w\[\e[00m\]\n\$(printf \"[\[\e[01;31m\]%.*s\[\e[00m\]]\" \$? \$?) \$ "

The trick is the newline. Emacs only erase last line colors.

Edoot
  • 111
  • 1