Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 2 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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.