2

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?

2 Answers 2

3
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

1
  • You need to put the definition of PS1 in single-quotes, or PWD'll be evaluated just once, when it's set. Oct 20, 2010 at 4:28
0

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

You must log in to answer this question.

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