Bash Path Prompt – How to Display the Absolute Path in Bash Prompt

bashpathprompt

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)?

Best Answer

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\$ '
Related Question