bug-bash
[Top][All Lists]
Advanced

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

Re: colored bash prompts seem to confuse readline


From: Greg Wooledge
Subject: Re: colored bash prompts seem to confuse readline
Date: Tue, 9 Feb 2010 13:09:18 -0500
User-agent: Mutt/1.4.2.3i

On Tue, Feb 09, 2010 at 08:39:49AM -0900, Britton Kerin wrote:
> Well ok its not just a plain colored prompt, what I would like to use is
> this:
> 
>     txtred='\e[0;31m' # Red
>     bldgrn='\e[1;32m' # Green
>     txtrst='\e[0m'    # Text Reset
>     PROMPT_COMMAND=' \
>         if [ $? -eq 0 ]; then \
>             PROMPT_PREFIX="$txtred"; \
>         else \
>             PROMPT_PREFIX="$bldgrn$? "; \
>         fi '
> 
>     PS1='$(echo -ne "$PROMPT_PREFIX")'"\$\[$txtrst\] "

Mixing PROMPT_COMMAND and PS1 is usually a bad idea.  You can do this
using PS1 alone.  Remember that all non-printing bytes must be enclosed
in literal \[ \] pairs.

red=$(tput setaf 1)
green=$(tput setaf 2)
reset=$(tput sgr0)
color=("$red" "$green")
PS1='\[${color[$?==0]}\]\u@\h:\w\$\[$reset\] '

(A bit confusing, using C-like evaluation where true is 1 and false is 0,
which is the opposite of bash... hence red being mapped to color[0]
instead of color[1].  But I hope you can understand it without further
explanation.)





reply via email to

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