Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to use the \w variable in .bashrc, but I want the prompt to highlight the current end-directory. Something like this:

/usr/local/<strong>bin</strong>

How can I do that?

share|improve this question
up vote 3 down vote accepted
PS1='${PWD%/*}/\[\e[33;1m\]${PWD##*/}\[\e[0m\] \$:  '

use bash'isms to manipulate the $PWD for the last component. COlorize, and add yet even more meta for bash escapes.

Substitute different numbers for 33 for different colors.

personally i hate the path in the prompt, it moves across the screen. I prefer in the titlebar.

PROMPT_COMMAND='echo -ne "\e]0;$USER@${HOSTNAME%%.*}: $(pwd -P)\a"'

EDIT changed Quotes on PS1 to single quotes, since it needs to be evaluated every time it's printed, not just once when it's read. Thanks @Gordon

share|improve this answer
    
You need to put the definition of PS1 in single-quotes, or PWD'll be evaluated just once, when it's set. – Gordon Davisson Oct 20 '10 at 4:28
    
Thanks a lot people! – Konzepz Oct 20 '10 at 8:21

Use something like $(dirname \w)/\[$(tput bold)\]$(basename \w)\[$(tput sgr0)\] in $PS1. Don't forget the single quotes.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .