Adding colour to prompt stops updating current directory

64 views Asked by At

My former prompt is this:

PS1='[\u@\h $(x=${PWD%/*}; echo ${x##*/}/${PWD##*/})] \! $ '

That is a monochrome prompt which will dynamically display the last 2 directories in the current working directory. I changed it to this to add colour:

PS1="\[\033[01;32m\]\u@\h\[\033[01;35m\] $(x=${PWD%/*}; echo ${x##*/}/${PWD##*/})\[\033[00m\] \! $ "

The colour works but the directory doesn't change as you cd around the system. Why not?

1

There are 1 answers

0
iamauser On BEST ANSWER

This one with single quote works fine :

 PS1='\[\033[01;32m\]\u@\h\[\033[01;35m\] $(x=${PWD%/*}; echo ${x##*/}/${PWD##*/})\[\033[00m\] \! $'