bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PS1 multiline with colors


From: Greg Wooledge
Subject: Re: PS1 multiline with colors
Date: Fri, 5 Jul 2013 08:30:48 -0400
User-agent: Mutt/1.4.2.3i

On Fri, Jul 05, 2013 at 12:21:13PM +0000, BASTIDON, Stéphane wrote:
> Now my case is a little more complex:
> I want my prompt changes colors according to $PWD Then I write something like 
> that:

This is the kind of thing where I suggest using PROMPT_COMMAND.

normal=$(tput sgr0) red=$(tput setaf 1) green=$(tput setaf 2) ...
PROMPT_COMMAND='
  case $PWD in
    /usr/local/*) color=$red ;;
    /var/*)       color=$green ;;
    ...
  esac
'
PS1='\u@\h:\[$color\]\w\[$normal\]\$ '
export normal red green ... PROMPT_COMMAND PS1

The PROMPT_COMMAND will be evaluated before PS1.  You can use it to set
variables that PS1 will use, all without the horrible speed penalty of
a fork/exec.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]