help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Expand a prompt string to calculate its length?


From: Jesse Hathaway
Subject: Re: [Help-bash] Expand a prompt string to calculate its length?
Date: Fri, 21 Jun 2019 09:46:31 -0500

Thanks Greg & Andy, sorry I missed the @P expansion in the man page,
but based on your informative posts I was able to get my PS1 working
correctly using that expansion.

On Wed, Jun 19, 2019 at 1:18 PM Andy Chu <address@hidden> wrote:
>
> The @P techniques works if you don't have color in your prompt.  If you have 
> colors I'm not sure there's a way to do it in general.
>
> The \[ and \] escape codes in PS1 are used to compensate for color when 
> passing to GNU readline.  They get translated to \0x00 and \0x01 if I 
> remember correctly.  GNU readline also has to have a notion of the prompt 
> width.
>
> Andy
>
>
>
>
>
>
>
> On Wed, Jun 19, 2019 at 11:14 AM Greg Wooledge <address@hidden> wrote:
>>
>> On Wed, Jun 19, 2019 at 01:09:33PM -0500, Jesse Hathaway wrote:
>> > Is there anyway to expand a partial prompt string to calculate its length?
>>
>> In bash 4.4 and above, yes.
>>
>> wooledg:~$ tmp=${PS1@P}; echo "<$PS1> <${#PS1}> <$tmp> <${#tmp}>"
>> <\h:\w\$ > <8> <wooledg:~$ > <11>
>>
>> The @P parameter expansion is one of the new "Parameter transformation"
>> options.
>>



reply via email to

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