I find under both shells and terms in Emacs my prompt does not appear as I would expect based on my $PS1 appears as...

# Shell under Emacs
]0;[email protected]: /home/[email protected]@583 ~ $ echo PS1
\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]

# Terminal under Emacs
0;[email protected]: /home/[email protected]@583 ~ $ echo PS1
\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]

# GNOME or xfce4 Terminal 
slackline@583 ~/ $ echo PS1
\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]

I set $PS1 in ~/.bashrc so that its sourced each time a shell is started (rather than login)...

$ grep PS1 ~/.bashrc
export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '

I found this thread which suggests its a down to differences between login and non-login shells and whether PS1 is being sourced from /etc/profile or a user-config, and suggests that under Emacs since its non-login its user configs that are used first. Checking /etc/profile to rule it out it has the following...

$ grep PS1 /etc/profile
if [ "$PS1" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
      PS1='# '
      PS1='$ '

...what is strange to me (if I've understood it correctly) is that \h:\w is commented out in this file and based on the above linked thread shouldn't be being sourced, yet it appears that this is what is being pre-pended to the prompt I would expect to see.

EDIT : This looks like a partial solution although I've given it a whirl and doesn't appear to have worked, will try again though.

EDIT2 : Found a solution to this problem and its down to how PROMPT_COMMAND is set...

if [ -z "$INSIDE_EMACS" ];
    export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'                       |                                                                                                         
    export PROMPT_COMMAND=''                                                                           

1 Answer 1


It looks like $PS1 does match: your echo statements in the first example return identical results. I think the problem is that the escape codes aren't getting processed properly. I use the following in my config:

;; translate control sequences as text is inserted in shell mode
(add-to-list 'comint-output-filter-functions 'ansi-color-process-output)

;; turn on color code support in shell mode

I don't use term, but it should be configurable as well.

  • Thanks for taking the time to look at this @Tyler I'll have a play around with your solution at some point, with the method of removing PROMPT_COMMAND under Emacs Terms/shells I still have colour prompts at present, but your proposal sounds useful to protect against problems in the future.
    – slackline
    Commented Aug 15, 2018 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.