bug-bash
[Top][All Lists]
Advanced

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

Re: Parameter operator P should probably strip \[ and \] characters


From: Chet Ramey
Subject: Re: Parameter operator P should probably strip \[ and \] characters
Date: Sat, 25 Mar 2017 15:16:31 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 3/24/17 11:57 PM, Torka Noda wrote:
> Hi,
> 
> (Currently using Bash-4.4_p12 on Gentoo GNU/Linux).
> 
> My PS1 contains colors, and thus \[ ... \] sequences around
> colors, for proper line wrapping on the command-line.
> 
> I want to fake this prompt from my ~/.bashrc, because OCD,
> before I execute some commands printing stuffs in the shell.
> 
> The problem is, using `echo -e "address@hidden"` will show
> glyphs for the non-printing characters "\[" and "\]", instead
> of stripping them.
> 
> From what I understand, \[ and \] characters are only useful for
> the prompts, right?

Yes, but one of the primary motivations for including the @P modifier
was requests to be able to use prompt expansions when using `read -e -p'.
In this case, you have to have the escape sequences preserved.

> If so, then the parameter operator P should probably strip them.

In general, you want the \[ and \] sequences expanded in all cases where
the result will eventually be fed to readline, and stripped when it is not.
It's not feasible for bash to figure that out for itself, so you have to
tell it.  Since those escape sequences get stripped when bash isn't going
to be doing line editing, you can put `set +o emacs +o vi' (or whichever
one is relevant for you) before expanding a string using the @P modifier
and get the results you want.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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