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;slackline@583.datascience.work.com: /home/slackline@samba.sheffield.work.comslackline@583 ~ $ echo PS1
\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]
# Terminal under Emacs
0;slackline@583.datascience.work.com: /home/slackline@samba.sheffield.work.comslackline@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" ];
then
export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' |
else
export PROMPT_COMMAND=''
fi