git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format

From
Piotr Krukowiecki <piotr.krukowiecki@gmail.com>
Date
Nov 28, 2012, 18:04 UTC
Message-ID
<CAA01CsouyXABkmbFy_u3Qt8R8W+1caxn34d5pscZSZJk9mynQg@mail.gmail.com>
In-Reply-To
<CAA01CspHAHN7se2oJ2WgcmpuRfoa+9Sx9sUvaPEmQ-Y+kDwHhA@mail.gmail.com>
Re-sending mail.

On Wed, Nov 28, 2012 at 7:02 PM, Piotr Krukowiecki <piotr.krukowiecki@gmail.com> wrote:

Show 60 quoted lines
>
> On Wed, Nov 28, 2012 at 2:20 PM, Simon Oosthoek <s.oosthoek@xs4all.nl> wrote:
>>
>> * Piotr Krukowiecki <piotr.krukowiecki@gmail.com> [2012-11-28 11:03:29 +0100]:
>>
>> > Hi,
>> >
>> > when I set PROMPT_COMMAND to __git_ps1 I get a space at the beginning:
>> >
>>
>> Is your setting?:
>> PROMPT_COMMAND=__git_ps1
>
>
> That's right
>
>
>> I believe you need to give 2 parameters in order to use it in PROMPT_COMMAND mode.
>
>
> Are you sure? git-prompt.sh says:
>
> #    3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1
> #        To customize the prompt, provide start/end arguments
> #        PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
>
> I interpret this as: if you don't want to customize the prompt, the simple "PROMPT_COMMAND=__git_ps1" is enough.
>
>>
>> >  (master)pkruk@foobar ~/dir$
>> > ^ space
>> >
>> > Is there a reason for this? It looks like a waste of space. If I'm not in
>> > git repository I don't have the space:
>> >
>> > pkruk@foobar ~/other$
>> >
>> > I noticed the space is explicitly specified in printf_format in
>> > git-prompt.sh. Is it needed? If I remove it, everything seems to work fine
>> > (no leading space)...
>> >
>> > --- /usr/local/src/git/git/contrib/completion/git-prompt.sh 2012-11-28
>> > 10:27:05.728939201 +0100
>> > +++ /home/pkruk/.git-prompt.sh 2012-11-28 10:52:56.852629745 +0100
>> > @@ -218,7 +218,7 @@ __git_ps1 ()
>> >   local detached=no
>> >   local ps1pc_start='\u@\h:\w '
>> >   local ps1pc_end='\$ '
>> > - local printf_format=' (%s)'
>> > + local printf_format='(%s)'
>> >
>> >   case "$#" in
>> >   2) pcmode=yes
>>
>>
>> These last 2 lines say: if 2 arguments are given, use pcmode. Otherwise you get command-subtitution mode, which gives weird effects when being called from PROMPT_COMMAND.
>>
>
> Still, it seems to work with above "patch"..
>

-- Piotr Krukowiecki

Previous: Simon OosthoekNext: Simon Oosthoek
Message 2 of 20 in “Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format”
  1. Simon OosthoekNov 28, 2012
  2. Piotr KrukowieckiNov 28, 2012
  3. Simon OosthoekNov 28, 2012
  4. Junio C HamanoNov 28, 2012
  5. Simon OosthoekNov 28, 2012
  6. Simon OosthoekDec 11, 2012
  7. Junio C HamanoDec 11, 2012
  8. Junio C HamanoDec 12, 2012
  9. Simon OosthoekDec 12, 2012
  10. Junio C HamanoDec 12, 2012
  11. Simon OosthoekDec 12, 2012
  12. Junio C HamanoDec 26, 2012
  13. Simon OosthoekDec 26, 2012
  14. make __git_ps1 accept a third parameter in pcmodeSimon Oosthoek, Dec 26, 2012
  15. Junio C HamanoDec 26, 2012
  16. Simon OosthoekDec 26, 2012
  17. Junio C HamanoDec 26, 2012
  18. Junio C HamanoDec 26, 2012
  19. Simon OosthoekDec 26, 2012
  20. Junio C HamanoDec 26, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.