bug-bash
[Top][All Lists]
Advanced

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

RE: PS1 multiline with colors


From: BASTIDON , Stéphane
Subject: RE: PS1 multiline with colors
Date: Fri, 5 Jul 2013 15:29:10 +0000

I'll try that asap ...
Thanks


-----Message d'origine-----
De : Greg Wooledge [mailto:wooledg@eeg.ccf.org] 
Envoyé : vendredi 5 juillet 2013 14:31
À : BASTIDON, Stéphane
Cc : bug-bash@gnu.org
Objet : Re: PS1 multiline with colors

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]