Bash – Emacs shell mode makes $PS1 different

bashcommand lineemacsprompt

I have a custom $PS1 variable that looks like this on my command line: enter image description here

And on emacs using M-x shell unfortunately looks like this: enter image description here

Here is my $PS1 variable export PS1='\[\e]0;\u@\h: \w\a\]\[\e[0;36m\]\T \[\e[1;30m\]\[\e[0;34m\]\u@\H\[\e[1;30m\] \[\e[0;32m\]\[\e[1;37m\]\w\[\e[0;37m\] \$ '

How can I make emacs shell-mode look the same with my CLI variable?

Best Answer

Leave the set title part to the terminals that support it:

case $TERM in
  (xterm*) set_title='\[\e]0;\u@\h: \w\a\]';;
  (*) set_title=
esac
PS1=$set_title'\[\e[0;36m\]\T \[\e[1;30m\]\[\e[0;34m\]\u@\H\[\e[1;30m\] \[\e[0;32m\]\[\e[1;37m\]\w\[\e[0;37m\] \$ '
Related Question