79

I currently have my bash PS1 set to something like this:

PS1="\[\`if [[ \$? = "0" ]]; then echo '\e[32m\h\e[0m'; else echo '\e[31m\h\e[0m' ; fi\`:\w\n\$ "

How can I make it show the absolute path instead of the relative one (e.g. /home/dave/dir instead of ~/dir)?

David B
  • 2,614

5 Answers5

83

Just replace \w with \$PWD:

PS1="\[\`if [[ \$? = "0" ]]; then echo '\e[32m\h\e[0m'; else echo '\e[31m\h\e[0m' ; fi\`:\$PWD\n\$ "

Anyway if you mind a little tip, I'd write something like:

PS1='\[`[ $? = 0 ] && X=2 || X=1; tput setaf $X`\]\h\[`tput sgr0`\]:$PWD\n\$ '
cYrus
  • 22,335
45

Put in your home .bashrc

PS1='\u@\h:\w\$ '
studiohack
  • 13,477
Alex
  • 451
7

Run pwd instead of using \W.

Simple version:

export PS1="\`pwd\` $ "

Using this in your code:

export PS1="\[\`if [[ \$? = "0" ]]; then echo '\e[32m\h\e[0m'; else echo '\e[31m\h\e[0m' ; fi\`:\`pwd\`\n\$ "
Doug Harris
  • 28,397
0

in bash's ps1; -W should be relative, and -w absolute, so in the above you should already have the absolute ?!

http://wiki.archlinux.org/index.php/Color_Bash_Prompt

Sirex
  • 11,214
0

Humm ~/dir is an absolute path but using a "shortcut". For instance, if you do cd /usr/local your prompt will most probably display the full path of /usr/local. So anyway, you have already a full path :-)

But probably your correct question is how to display the full path without any shortcuts like ~?

However, I don't know an answer for that one and looking at the man, it does seem to have one (at least documented).

Huygens
  • 1,489