{"thread":{"id":"32226","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","startedAt":"2012-11-28T13:20:34Z","lastAt":"2012-12-26T21:03:24Z","messageCount":20,"participants":["Simon Oosthoek","Piotr Krukowiecki","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"204157","messageId":"20121128132033.GA10082@xs4all.nl","threadId":"32226","inReplyTo":"CAA01Cso1E4EC4W667FEU_af2=uGOfPuaWEB3y+zPCpB+bPzoaA@mail.gmail.com","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-11-28T13:20:34Z","receivedAt":"2012-11-28T13:20:34Z","isPatch":false,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"* Piotr Krukowiecki <piotr.krukowiecki@gmail.com> [2012-11-28 11:03:29 +0100]:\n\n> Hi,\n> \n> when I set PROMPT_COMMAND to __git_ps1 I get a space at the beginning:\n> \n\nIs your setting?:\nPROMPT_COMMAND=__git_ps1\n\nI believe you need to give 2 parameters in order to use it in PROMPT_COMMAND mode.\n\nIn my .bashrc I have:\nif [ -f ~/.gitprompt.sh ]\nthen\n        . ~/.gitprompt.sh\n        GIT_PS1_SHOWDIRTYSTATE=true\n        GIT_PS1_SHOWCOLORHINTS=true\n        GIT_PS1_SHOWUNTRACKEDFILES=true\n        PROMPT_COMMAND=\"__git_ps1 '\\u@\\[\\e[1;34m\\]\\h\\[\\e[0m\\]:\\w' '\\\\\\$ '\"\nfi\n\n\n>  (master)pkruk@foobar ~/dir$\n> ^ space\n> \n> Is there a reason for this? It looks like a waste of space. If I'm not in\n> git repository I don't have the space:\n> \n> pkruk@foobar ~/other$\n> \n> I noticed the space is explicitly specified in printf_format in\n> git-prompt.sh. Is it needed? If I remove it, everything seems to work fine\n> (no leading space)...\n> \n> --- /usr/local/src/git/git/contrib/completion/git-prompt.sh 2012-11-28\n> 10:27:05.728939201 +0100\n> +++ /home/pkruk/.git-prompt.sh 2012-11-28 10:52:56.852629745 +0100\n> @@ -218,7 +218,7 @@ __git_ps1 ()\n>   local detached=no\n>   local ps1pc_start='\\u@\\h:\\w '\n>   local ps1pc_end='\\$ '\n> - local printf_format=' (%s)'\n> + local printf_format='(%s)'\n> \n>   case \"$#\" in\n>   2) pcmode=yes\n\n\nThese 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.\n\nCheers\n\nSimon\n"},{"id":"204173","messageId":"CAA01CsouyXABkmbFy_u3Qt8R8W+1caxn34d5pscZSZJk9mynQg@mail.gmail.com","threadId":"32226","inReplyTo":"CAA01CspHAHN7se2oJ2WgcmpuRfoa+9Sx9sUvaPEmQ-Y+kDwHhA@mail.gmail.com","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Piotr Krukowiecki","fromEmail":"piotr.krukowiecki@gmail.com","sentAt":"2012-11-28T18:04:40Z","receivedAt":"2012-11-28T18:04:40Z","isPatch":false,"sender":{"key":"piotr.krukowiecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3259959?v=4"},"body":"Re-sending mail.\n\nOn Wed, Nov 28, 2012 at 7:02 PM, Piotr Krukowiecki\n<piotr.krukowiecki@gmail.com> wrote:\n>\n> On Wed, Nov 28, 2012 at 2:20 PM, Simon Oosthoek <s.oosthoek@xs4all.nl> wrote:\n>>\n>> * Piotr Krukowiecki <piotr.krukowiecki@gmail.com> [2012-11-28 11:03:29 +0100]:\n>>\n>> > Hi,\n>> >\n>> > when I set PROMPT_COMMAND to __git_ps1 I get a space at the beginning:\n>> >\n>>\n>> Is your setting?:\n>> PROMPT_COMMAND=__git_ps1\n>\n>\n> That's right\n>\n>\n>> I believe you need to give 2 parameters in order to use it in PROMPT_COMMAND mode.\n>\n>\n> Are you sure? git-prompt.sh says:\n>\n> #    3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1\n> #        To customize the prompt, provide start/end arguments\n> #        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n>\n> I interpret this as: if you don't want to customize the prompt, the simple \"PROMPT_COMMAND=__git_ps1\" is enough.\n>\n>>\n>> >  (master)pkruk@foobar ~/dir$\n>> > ^ space\n>> >\n>> > Is there a reason for this? It looks like a waste of space. If I'm not in\n>> > git repository I don't have the space:\n>> >\n>> > pkruk@foobar ~/other$\n>> >\n>> > I noticed the space is explicitly specified in printf_format in\n>> > git-prompt.sh. Is it needed? If I remove it, everything seems to work fine\n>> > (no leading space)...\n>> >\n>> > --- /usr/local/src/git/git/contrib/completion/git-prompt.sh 2012-11-28\n>> > 10:27:05.728939201 +0100\n>> > +++ /home/pkruk/.git-prompt.sh 2012-11-28 10:52:56.852629745 +0100\n>> > @@ -218,7 +218,7 @@ __git_ps1 ()\n>> >   local detached=no\n>> >   local ps1pc_start='\\u@\\h:\\w '\n>> >   local ps1pc_end='\\$ '\n>> > - local printf_format=' (%s)'\n>> > + local printf_format='(%s)'\n>> >\n>> >   case \"$#\" in\n>> >   2) pcmode=yes\n>>\n>>\n>> 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.\n>>\n>\n> Still, it seems to work with above \"patch\"..\n>\n\n\n\n\n--\nPiotr Krukowiecki\n"},{"id":"204197","messageId":"50B66F41.1030305@xs4all.nl","threadId":"32226","inReplyTo":"CAA01CspHAHN7se2oJ2WgcmpuRfoa+9Sx9sUvaPEmQ-Y+kDwHhA@mail.gmail.com","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-11-28T20:08:33Z","receivedAt":"2012-11-28T20:08:33Z","isPatch":false,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"On 28/11/12 19:02, Piotr Krukowiecki wrote:\n>     Is your setting?:\n>     PROMPT_COMMAND=__git_ps1\n> \n> \n> That's right\n>  \n> \n>     I believe you need to give 2 parameters in order to use it in\n>     PROMPT_COMMAND mode.\n> \n> \n> Are you sure? git-prompt.sh says:\n> \n> #    3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1\n> #        To customize the prompt, provide start/end arguments\n> #        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n> \n> I interpret this as: if you don't want to customize the prompt, the\n> simple \"PROMPT_COMMAND=__git_ps1\" is enough.\n>  \n\nI'm sure, although you're right this documentation is wrong...\nI guess it must have slipped by when the final changes were made to the\ncode. (The requirement to have 2 arguments for PROMPT_COMMAND mode were\none of the last changes before being accepted into the release process.)\n\nI've been too busy with other stuff to take another look at this in the\nmeantime.\n\nperhaps the point should read like this:\n#    3a) In ~/.bashrc set PROMPT_COMMAND\n#        To customize the prompt, provide start/end arguments\n#        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n\nWhich would not be confusing at all, I think...\n\n> \n> \n>     These last 2 lines say: if 2 arguments are given, use pcmode.\n>     Otherwise you get command-subtitution mode, which gives weird\n>     effects when being called from PROMPT_COMMAND.\n> \n> \n> Still, it seems to work with above \"patch\"..\n\nIt only works in your specific case, since you're expecting the branch\ninfo before the rest of your prompt. The output comes from the part of\nthe code that is meant for substitution mode ;-)\n\nCheers\n\nSimon\n"},{"id":"204203","messageId":"7vlidltpyj.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"50B66F41.1030305@xs4all.nl","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-11-28T20:47:16Z","receivedAt":"2012-11-28T20:47:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n\n> perhaps the point should read like this:\n> #    3a) In ~/.bashrc set PROMPT_COMMAND\n> #        To customize the prompt, provide start/end arguments\n> #        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n>\n> Which would not be confusing at all, I think...\n\nIt says \"to customize\", so a user who just wants the default (which\ndoes not exist but the comment does not say so) would be left\nwithout instruction, no?\n\n    In $HOME/.bashrc, PROMPT_COMMAND can be set to\n    '__git_ps1 <pre> <post>', where <pre> and <post>\n    are strings you would put in $PS1 before and after\n    the status string generated by git-prompt machinery.\n    e.g.\n        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n\nor something?\n"},{"id":"204204","messageId":"50B67AEB.1000603@xs4all.nl","threadId":"32226","inReplyTo":"7vlidltpyj.fsf@alter.siamese.dyndns.org","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-11-28T20:58:19Z","receivedAt":"2012-11-28T20:58:19Z","isPatch":false,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"On 28/11/12 21:47, Junio C Hamano wrote:\n> Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n> \n>> perhaps the point should read like this:\n>> #    3a) In ~/.bashrc set PROMPT_COMMAND\n>> #        To customize the prompt, provide start/end arguments\n>> #        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n>>\n>> Which would not be confusing at all, I think...\n> \n> It says \"to customize\", so a user who just wants the default (which\n> does not exist but the comment does not say so) would be left\n> without instruction, no?\n> \n>     In $HOME/.bashrc, PROMPT_COMMAND can be set to\n>     '__git_ps1 <pre> <post>', where <pre> and <post>\n>     are strings you would put in $PS1 before and after\n>     the status string generated by git-prompt machinery.\n>     e.g.\n>         PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n> \n> or something?\n> \n\nLooks better than my suggestion :-)\n\nthanks\n\n/Simon\n"},{"id":"204703","messageId":"50C7B811.7030006@xs4all.nl","threadId":"32226","inReplyTo":"7vlidltpyj.fsf@alter.siamese.dyndns.org","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-12-11T22:47:45Z","receivedAt":"2012-12-11T22:47:45Z","isPatch":false,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"Hi Junio\n\nThis patch for the documentation doesn't seem to be in rc2 of 1.8.1...\n\ntonight I was explaining this feature to a small group of people and I\npulled the git tree to get the latest code.\n\nThe current tagged 1.8.1-rc2 doesn't yet have your improvement and after\ntrying to explain it, I think it should be improved even more ;-)\n\nI'm sorry to say I don't have the time right now to make a proper patch,\nbut I'll try to expand below...\n\nOn 28/11/12 21:47, Junio C Hamano wrote:\n> Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n> \n>> perhaps the point should read like this:\n>> #    3a) In ~/.bashrc set PROMPT_COMMAND\n>> #        To customize the prompt, provide start/end arguments\n>> #        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n>>\n>> Which would not be confusing at all, I think...\n> \n> It says \"to customize\", so a user who just wants the default (which\n> does not exist but the comment does not say so) would be left\n> without instruction, no?\n> \n>     In $HOME/.bashrc, PROMPT_COMMAND can be set to\n>     '__git_ps1 <pre> <post>', where <pre> and <post>\n>     are strings you would put in $PS1 before and after\n>     the status string generated by git-prompt machinery.\n>     e.g.\n>         PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n> \n> or something?\n> \n\nThe gist should be that:\n__git_ps1 can function in two modes; The \"traditional\" way with command\nsubstitution. This mode is activated when the function is provided 0 or\n1 arguments. The new way, activated by providing exactly 2 arguments to\n__git_ps1 is intended for use in the PROMPT_COMMAND way of bash to call\na function before writing the prompt. This command can then be (and is\nin fact) used to set/overwrite the PS1 variable.\n\nOnly in the PROMPT_COMMAND mode can you get a prompt with colors for the\nvarious states of the git tree showing in the prompt.\n\nAn example for inclusion in the ~/.bashrc file is:\n-----snip-----\nPROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\nGIT_PS1_SHOWDIRTYSTATE=true\nGIT_PS1_SHOWCOLORHINTS=true\n--------------\n\nIt turns out that it can be quite confusing to get your head around this\nsplit personality of __git_ps1...\n\nI hope you can somehow get this into the next release with some\nimprovement to the docs!\n\nCheers\n\nSimon\n"},{"id":"204704","messageId":"7v7goo6vi3.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"50C7B811.7030006@xs4all.nl","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-11T23:04:36Z","receivedAt":"2012-12-11T23:04:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n\n> This patch for the documentation doesn't seem to be in rc2 of 1.8.1...\n\nThere wasn't any patch, and after sending \"something like this\" I\nforgot about the topic, as usual.\n\n> The current tagged 1.8.1-rc2 doesn't yet have your improvement and after\n> trying to explain it, I think it should be improved even more ;-)\n\nI am not sure what \"my improvement\" you are refering to.  Is it only\nabout how the usage appears in the comment?\n\nPerhaps like this?  I think the straight-forward one should be\nlisted as the primary usage, and the confusing one should be an\nalternate for advanced users, so 3a/3b have been swapped.\n\n contrib/completion/git-prompt.sh | 16 +++++++++++-----\n 1 file changed, 11 insertions(+), 5 deletions(-)\n\ndiff --git i/contrib/completion/git-prompt.sh w/contrib/completion/git-prompt.sh\nindex 00fc099..899eb09 100644\n--- i/contrib/completion/git-prompt.sh\n+++ w/contrib/completion/git-prompt.sh\n@@ -10,14 +10,20 @@\n #    1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).\n #    2) Add the following line to your .bashrc/.zshrc:\n #        source ~/.git-prompt.sh\n-#    3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1\n-#        To customize the prompt, provide start/end arguments\n-#        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n-#    3b) Alternatively change your PS1 to call __git_ps1 as\n+#    3a) Change your PS1 to call __git_ps1 as\n #        command-substitution:\n #        Bash: PS1='[\\u@\\h \\W$(__git_ps1 \" (%s)\")]\\$ '\n #        ZSH:  PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n-#        the optional argument will be used as format string\n+#        the optional argument will be used as format string.\n+#    3b) Alternatively, if you are using bash, __git_ps1 can be\n+#        used for PROMPT_COMMAND with two parameters, <pre> and\n+#        <post>, which are strings you would put in $PS1 before\n+#        and after the status string generated by the git-prompt\n+#        machinery.  e.g.\n+#           PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n+#        will show username, at-sign, host, colon, cwd, then\n+#        various status string, followed by dollar and SP, as\n+#        your prompt.\n #\n # The argument to __git_ps1 will be displayed only if you are currently\n # in a git repository.  The %s token will be the name of the current\n"},{"id":"204707","messageId":"7vy5h45e7b.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"7v7goo6vi3.fsf@alter.siamese.dyndns.org","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-12T00:03:36Z","receivedAt":"2012-12-12T00:03:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Perhaps like this?\n\nOK, this time with a log message.\n\n-- >8 --\nSubject: [PATCH] git-prompt.sh: update PROMPT_COMMAND documentation\n\nThe description of __git_ps1 function operating in two-arg mode was\nnot very clear.  It said \"set PROMPT_COMMAND=__git_ps1\" which is not\nthe right usage for this mode, followed by \"To customize the prompt,\ndo this\", giving a false impression that those who do not want to\ncustomize it can get away with no-arg form, which was incorrect.\n\nMake it clear that this mode always takes two arguments, pre and\npost, with an example.\n\nThe straight-forward one should be listed as the primary usage, and\nthe confusing one should be an alternate for advanced users.  Swap\nthe order of these two.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n contrib/completion/git-prompt.sh | 16 +++++++++++-----\n 1 file changed, 11 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex a8b53ba..9b074e1 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -10,14 +10,20 @@\n #    1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).\n #    2) Add the following line to your .bashrc/.zshrc:\n #        source ~/.git-prompt.sh\n-#    3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1\n-#        To customize the prompt, provide start/end arguments\n-#        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n-#    3b) Alternatively change your PS1 to call __git_ps1 as\n+#    3a) Change your PS1 to call __git_ps1 as\n #        command-substitution:\n #        Bash: PS1='[\\u@\\h \\W$(__git_ps1 \" (%s)\")]\\$ '\n #        ZSH:  PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n-#        the optional argument will be used as format string\n+#        the optional argument will be used as format string.\n+#    3b) Alternatively, if you are using bash, __git_ps1 can be\n+#        used for PROMPT_COMMAND with two parameters, <pre> and\n+#        <post>, which are strings you would put in $PS1 before\n+#        and after the status string generated by the git-prompt\n+#        machinery.  e.g.\n+#           PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n+#        will show username, at-sign, host, colon, cwd, then\n+#        various status string, followed by dollar and SP, as\n+#        your prompt.\n #\n # The argument to __git_ps1 will be displayed only if you are currently\n # in a git repository.  The %s token will be the name of the current\n-- \n1.8.1.rc1.128.gd8d1528\n"},{"id":"204723","messageId":"20121212085507.GA32187@xs4all.nl","threadId":"32226","inReplyTo":"7vy5h45e7b.fsf@alter.siamese.dyndns.org","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-12-12T08:55:07Z","receivedAt":"2012-12-12T08:55:07Z","isPatch":false,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"Hi Junio\n\nThis removes most of the ambiguities :-)\nAck from me!\n\nI still have some minor nits, but I'll leave that for another time when I'm less busy.\n\nBTW, I haven't tried this yet, but if you pass 2 arguments to __git_ps1 when called from command-substition mode, I suppose it will think it's in PC mode and overwrite the PS1!\n\nAt some point, I'd like to see this code split off into \"pc\" and \"cs\" functions which call a common function to get the git status. But that's a major rewrite and it may involve more overhead, since each function should process the output of the common function in a different way.\n\nCheers\n\nSimon\n\n* Junio C Hamano <gitster@pobox.com> [2012-12-11 16:03:36 -0800]:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n> > Perhaps like this?\n> \n> OK, this time with a log message.\n> \n> -- >8 --\n> Subject: [PATCH] git-prompt.sh: update PROMPT_COMMAND documentation\n> \n> The description of __git_ps1 function operating in two-arg mode was\n> not very clear.  It said \"set PROMPT_COMMAND=__git_ps1\" which is not\n> the right usage for this mode, followed by \"To customize the prompt,\n> do this\", giving a false impression that those who do not want to\n> customize it can get away with no-arg form, which was incorrect.\n> \n> Make it clear that this mode always takes two arguments, pre and\n> post, with an example.\n> \n> The straight-forward one should be listed as the primary usage, and\n> the confusing one should be an alternate for advanced users.  Swap\n> the order of these two.\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  contrib/completion/git-prompt.sh | 16 +++++++++++-----\n>  1 file changed, 11 insertions(+), 5 deletions(-)\n> \n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index a8b53ba..9b074e1 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -10,14 +10,20 @@\n>  #    1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).\n>  #    2) Add the following line to your .bashrc/.zshrc:\n>  #        source ~/.git-prompt.sh\n> -#    3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1\n> -#        To customize the prompt, provide start/end arguments\n> -#        PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n> -#    3b) Alternatively change your PS1 to call __git_ps1 as\n> +#    3a) Change your PS1 to call __git_ps1 as\n>  #        command-substitution:\n>  #        Bash: PS1='[\\u@\\h \\W$(__git_ps1 \" (%s)\")]\\$ '\n>  #        ZSH:  PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n> -#        the optional argument will be used as format string\n> +#        the optional argument will be used as format string.\n> +#    3b) Alternatively, if you are using bash, __git_ps1 can be\n> +#        used for PROMPT_COMMAND with two parameters, <pre> and\n> +#        <post>, which are strings you would put in $PS1 before\n> +#        and after the status string generated by the git-prompt\n> +#        machinery.  e.g.\n> +#           PROMPT_COMMAND='__git_ps1 \"\\u@\\h:\\w\" \"\\\\\\$ \"'\n> +#        will show username, at-sign, host, colon, cwd, then\n> +#        various status string, followed by dollar and SP, as\n> +#        your prompt.\n>  #\n>  # The argument to __git_ps1 will be displayed only if you are currently\n>  # in a git repository.  The %s token will be the name of the current\n> -- \n> 1.8.1.rc1.128.gd8d1528\n> \n"},{"id":"204762","messageId":"7vlid35fe4.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"20121212085507.GA32187@xs4all.nl","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-12T17:50:11Z","receivedAt":"2012-12-12T17:50:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n\n> This removes most of the ambiguities :-)\n> Ack from me!\n\nOK, as this is a low-impact finishing touch for a new feature, I'll\nfast-track this to 'master' before the final release.\n\nThanks.\n"},{"id":"204781","messageId":"50C8E857.5080000@xs4all.nl","threadId":"32226","inReplyTo":"7vlid35fe4.fsf@alter.siamese.dyndns.org","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-12-12T20:25:59Z","receivedAt":"2012-12-12T20:25:59Z","isPatch":false,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"On 12/12/12 18:50, Junio C Hamano wrote:\n> Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n> \n>> This removes most of the ambiguities :-)\n>> Ack from me!\n> \n> OK, as this is a low-impact finishing touch for a new feature, I'll\n> fast-track this to 'master' before the final release.\n> \n\nOk, wonderful!\nBTW, I tried the thing I mentioned and it was safe to do:\nPS1='blabla$(__git_ps1 x y)blabla'\nwill not eat your prompt, although I'd recommend putting something\nuseful instead of blabla ;-)\n\nCheers\n\nSimon\n"},{"id":"205488","messageId":"7vvcbpp846.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"50C8E857.5080000@xs4all.nl","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-26T07:47:53Z","receivedAt":"2012-12-26T07:47:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n\n> On 12/12/12 18:50, Junio C Hamano wrote:\n>> Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n>> \n>>> This removes most of the ambiguities :-)\n>>> Ack from me!\n>> \n>> OK, as this is a low-impact finishing touch for a new feature, I'll\n>> fast-track this to 'master' before the final release.\n>> \n>\n> Ok, wonderful!\n> BTW, I tried the thing I mentioned and it was safe to do:\n> PS1='blabla$(__git_ps1 x y)blabla'\n> will not eat your prompt, although I'd recommend putting something\n> useful instead of blabla ;-)\n\nActually, I deeply regret merging this to 'master'.  The original\n\"as a command substitution in PS1\" mode, you could add anything\naround the status string, so I could do:\n\n\tPS1=': \\h \\W$(__git_ps1 \"/%s\"); '\n\nto get something like:\n\n\t: hostname dirname/<STATUS>; <CURSOR HERE>\n\nIn the new PROMPT_COMMAND mode, there is always parentheses around\nthe status string (and an SP before the parenthesees) that the user\ncannot get rid of.\n\nThis is not a usability regression per-se (if you do not like the\nextra parentheses, you do not have to use the colored mode), but is\nsomething that will make me never use the mode.\n\nCan we make it take an optional third parameter so that we could say\n\n\tPROMPT_COMMAND='__git_ps1 \": \\h \\W\" \"; \" \"/%s\"'\n\nto do the same as what the command substitution mode would have\ngiven for\n\n\tPS1=': \\h \\W$(__git_ps1 \"/%s\"); '\n\nperhaps?\n\nTotally untested, but perhaps along this line.\n\n contrib/completion/git-prompt.sh | 24 ++++++++++++++----------\n 1 file changed, 14 insertions(+), 10 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 9b074e1..b2579f4 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -236,9 +236,10 @@ __git_ps1 ()\n \tlocal printf_format=' (%s)'\n \n \tcase \"$#\" in\n-\t\t2)\tpcmode=yes\n+\t\t2|3)\tpcmode=yes\n \t\t\tps1pc_start=\"$1\"\n \t\t\tps1pc_end=\"$2\"\n+\t\t\tprintf_format=\"${3:-$printf_format}\"\n \t\t;;\n \t\t0|1)\tprintf_format=\"${1:-$printf_format}\"\n \t\t;;\n@@ -339,6 +340,7 @@ __git_ps1 ()\n \n \t\tlocal f=\"$w$i$s$u\"\n \t\tif [ $pcmode = yes ]; then\n+\t\t\tlocal ps1=\n \t\t\tif [ -n \"${GIT_PS1_SHOWCOLORHINTS-}\" ]; then\n \t\t\t\tlocal c_red='\\e[31m'\n \t\t\t\tlocal c_green='\\e[32m'\n@@ -356,29 +358,31 @@ __git_ps1 ()\n \t\t\t\t\tbranch_color=\"$bad_color\"\n \t\t\t\tfi\n \n-\t\t\t\t# Setting PS1 directly with \\[ and \\] around colors\n+\t\t\t\t# Setting ps1 directly with \\[ and \\] around colors\n \t\t\t\t# is necessary to prevent wrapping issues!\n-\t\t\t\tPS1=\"$ps1pc_start (\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n+\t\t\t\tps1=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n \n \t\t\t\tif [ -n \"$w$i$s$u$r$p\" ]; then\n-\t\t\t\t\tPS1=\"$PS1 \"\n+\t\t\t\t\tps1=\"$ps1 \"\t\t\t\t\t\n \t\t\t\tfi\n \t\t\t\tif [ \"$w\" = \"*\" ]; then\n-\t\t\t\t\tPS1=\"$PS1\\[$bad_color\\]$w\"\n+\t\t\t\t\tps1=\"$ps1\\[$bad_color\\]$w\"\n \t\t\t\tfi\n \t\t\t\tif [ -n \"$i\" ]; then\n-\t\t\t\t\tPS1=\"$PS1\\[$ok_color\\]$i\"\n+\t\t\t\t\tps1=\"$ps1\\[$ok_color\\]$i\"\n \t\t\t\tfi\n \t\t\t\tif [ -n \"$s\" ]; then\n-\t\t\t\t\tPS1=\"$PS1\\[$flags_color\\]$s\"\n+\t\t\t\t\tps1=\"$ps1\\[$flags_color\\]$s\"\n \t\t\t\tfi\n \t\t\t\tif [ -n \"$u\" ]; then\n-\t\t\t\t\tPS1=\"$PS1\\[$bad_color\\]$u\"\n+\t\t\t\t\tps1=\"$ps1\\[$bad_color\\]$u\"\n \t\t\t\tfi\n-\t\t\t\tPS1=\"$PS1\\[$c_clear\\]$r$p)$ps1pc_end\"\n+\t\t\t\tps1=\"$ps1\\[$c_clear\\]$r$p\"\n \t\t\telse\n-\t\t\t\tPS1=\"$ps1pc_start ($c${b##refs/heads/}${f:+ $f}$r$p)$ps1pc_end\"\n+\t\t\t\tps1=\"$c${b##refs/heads/}${f:+ $f}$r$p\"\n \t\t\tfi\n+\t\t\tps1=$(printf -- \"$printf_format\" \"$ps1\")\n+\t\t\tPS1=\"$ps1pc_start$ps1$ps1pc_end\"\n \t\telse\n \t\t\t# NO color option unless in PROMPT_COMMAND mode\n \t\t\tprintf -- \"$printf_format\" \"$c${b##refs/heads/}${f:+ $f}$r$p\"\n"},{"id":"205493","messageId":"20121226125120.GA16990@xs4all.nl","threadId":"32226","inReplyTo":"7vvcbpp846.fsf@alter.siamese.dyndns.org","subject":"Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-12-26T12:51:20Z","receivedAt":"2012-12-26T12:51:20Z","isPatch":false,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"* Junio C Hamano <gitster@pobox.com> [2012-12-25 23:47:53 -0800]:\n \n> Can we make it take an optional third parameter so that we could say\n> \n> \tPROMPT_COMMAND='__git_ps1 \": \\h \\W\" \"; \" \"/%s\"'\n> \n> to do the same as what the command substitution mode would have\n> given for\n> \n> \tPS1=': \\h \\W$(__git_ps1 \"/%s\"); '\n> \n> perhaps?\n> \n> Totally untested, but perhaps along this line.\n> \n\nI tried your patch and (to my surprise, after the first reading) it worked.\n\nI've further modified git-prompt.sh to include more usage text and I changed\nthe name of ps1 to gitstring, as it might be confused with PS1 upon casual\nreading.\n\nI'll be sending a format-patch patchmail ASAP...\n\n\n>  contrib/completion/git-prompt.sh | 24 ++++++++++++++----------\n>  1 file changed, 14 insertions(+), 10 deletions(-)\n> \n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 9b074e1..b2579f4 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -236,9 +236,10 @@ __git_ps1 ()\n>  \tlocal printf_format=' (%s)'\n>  \n>  \tcase \"$#\" in\n> -\t\t2)\tpcmode=yes\n> +\t\t2|3)\tpcmode=yes\n>  \t\t\tps1pc_start=\"$1\"\n>  \t\t\tps1pc_end=\"$2\"\n> +\t\t\tprintf_format=\"${3:-$printf_format}\"\n>  \t\t;;\n>  \t\t0|1)\tprintf_format=\"${1:-$printf_format}\"\n>  \t\t;;\n> @@ -339,6 +340,7 @@ __git_ps1 ()\n>  \n>  \t\tlocal f=\"$w$i$s$u\"\n>  \t\tif [ $pcmode = yes ]; then\n> +\t\t\tlocal ps1=\n>  \t\t\tif [ -n \"${GIT_PS1_SHOWCOLORHINTS-}\" ]; then\n>  \t\t\t\tlocal c_red='\\e[31m'\n>  \t\t\t\tlocal c_green='\\e[32m'\n> @@ -356,29 +358,31 @@ __git_ps1 ()\n>  \t\t\t\t\tbranch_color=\"$bad_color\"\n>  \t\t\t\tfi\n>  \n> -\t\t\t\t# Setting PS1 directly with \\[ and \\] around colors\n> +\t\t\t\t# Setting ps1 directly with \\[ and \\] around colors\n>  \t\t\t\t# is necessary to prevent wrapping issues!\n> -\t\t\t\tPS1=\"$ps1pc_start (\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n> +\t\t\t\tps1=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n>  \n>  \t\t\t\tif [ -n \"$w$i$s$u$r$p\" ]; then\n> -\t\t\t\t\tPS1=\"$PS1 \"\n> +\t\t\t\t\tps1=\"$ps1 \"\t\t\t\t\t\n>  \t\t\t\tfi\n>  \t\t\t\tif [ \"$w\" = \"*\" ]; then\n> -\t\t\t\t\tPS1=\"$PS1\\[$bad_color\\]$w\"\n> +\t\t\t\t\tps1=\"$ps1\\[$bad_color\\]$w\"\n>  \t\t\t\tfi\n>  \t\t\t\tif [ -n \"$i\" ]; then\n> -\t\t\t\t\tPS1=\"$PS1\\[$ok_color\\]$i\"\n> +\t\t\t\t\tps1=\"$ps1\\[$ok_color\\]$i\"\n>  \t\t\t\tfi\n>  \t\t\t\tif [ -n \"$s\" ]; then\n> -\t\t\t\t\tPS1=\"$PS1\\[$flags_color\\]$s\"\n> +\t\t\t\t\tps1=\"$ps1\\[$flags_color\\]$s\"\n>  \t\t\t\tfi\n>  \t\t\t\tif [ -n \"$u\" ]; then\n> -\t\t\t\t\tPS1=\"$PS1\\[$bad_color\\]$u\"\n> +\t\t\t\t\tps1=\"$ps1\\[$bad_color\\]$u\"\n>  \t\t\t\tfi\n> -\t\t\t\tPS1=\"$PS1\\[$c_clear\\]$r$p)$ps1pc_end\"\n> +\t\t\t\tps1=\"$ps1\\[$c_clear\\]$r$p\"\n>  \t\t\telse\n> -\t\t\t\tPS1=\"$ps1pc_start ($c${b##refs/heads/}${f:+ $f}$r$p)$ps1pc_end\"\n> +\t\t\t\tps1=\"$c${b##refs/heads/}${f:+ $f}$r$p\"\n>  \t\t\tfi\n> +\t\t\tps1=$(printf -- \"$printf_format\" \"$ps1\")\n> +\t\t\tPS1=\"$ps1pc_start$ps1$ps1pc_end\"\n>  \t\telse\n>  \t\t\t# NO color option unless in PROMPT_COMMAND mode\n>  \t\t\tprintf -- \"$printf_format\" \"$c${b##refs/heads/}${f:+ $f}$r$p\"\n\n/Simon\n"},{"id":"205501","messageId":"20121226191505.GA29210@simaj.xs4all.nl","threadId":"32226","inReplyTo":"7vvcbpp846.fsf@alter.siamese.dyndns.org","subject":"[PATCH] make __git_ps1 accept a third parameter in pcmode","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-12-26T19:15:05Z","receivedAt":"2012-12-26T19:15:05Z","isPatch":true,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"The optional third parameter when __git_ps1 is used in\nPROMPT_COMMAND mode as format string for printf to further\ncustomize the way the git status string is embedded in the\nuser's PS1 prompt.\n\nSigned-off-by: Simon Oosthoek <s.oosthoek@xs4all.nl>\n---\n contrib/completion/git-prompt.sh |   32 ++++++++++++++++++++------------\n 1 file changed, 20 insertions(+), 12 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 9b074e1..2922bb3 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -24,6 +24,8 @@\n #        will show username, at-sign, host, colon, cwd, then\n #        various status string, followed by dollar and SP, as\n #        your prompt.\n+#        Optionally, you can supply a third argument with a printf\n+#        format string to finetune the output of the branch status\n #\n # The argument to __git_ps1 will be displayed only if you are currently\n # in a git repository.  The %s token will be the name of the current\n@@ -222,10 +224,12 @@ __git_ps1_show_upstream ()\n # when called from PS1 using command substitution\n # in this mode it prints text to add to bash PS1 prompt (includes branch name)\n #\n-# __git_ps1 requires 2 arguments when called from PROMPT_COMMAND (pc)\n+# __git_ps1 requires 2 or 3 arguments when called from PROMPT_COMMAND (pc)\n # in that case it _sets_ PS1. The arguments are parts of a PS1 string.\n-# when both arguments are given, the first is prepended and the second appended\n+# when two arguments are given, the first is prepended and the second appended\n # to the state string when assigned to PS1.\n+# The optional third parameter will be used as printf format string to further\n+# customize the output of the git-status string.\n # In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true\n __git_ps1 ()\n {\n@@ -236,9 +240,10 @@ __git_ps1 ()\n \tlocal printf_format=' (%s)'\n \n \tcase \"$#\" in\n-\t\t2)\tpcmode=yes\n+\t\t2|3)\tpcmode=yes\n \t\t\tps1pc_start=\"$1\"\n \t\t\tps1pc_end=\"$2\"\n+\t\t\tprintf_format=\"${3:-$printf_format}\"\n \t\t;;\n \t\t0|1)\tprintf_format=\"${1:-$printf_format}\"\n \t\t;;\n@@ -339,6 +344,7 @@ __git_ps1 ()\n \n \t\tlocal f=\"$w$i$s$u\"\n \t\tif [ $pcmode = yes ]; then\n+\t\t\tlocal gitstring=\n \t\t\tif [ -n \"${GIT_PS1_SHOWCOLORHINTS-}\" ]; then\n \t\t\t\tlocal c_red='\\e[31m'\n \t\t\t\tlocal c_green='\\e[32m'\n@@ -356,29 +362,31 @@ __git_ps1 ()\n \t\t\t\t\tbranch_color=\"$bad_color\"\n \t\t\t\tfi\n \n-\t\t\t\t# Setting PS1 directly with \\[ and \\] around colors\n+\t\t\t\t# Setting gitstring directly with \\[ and \\] around colors\n \t\t\t\t# is necessary to prevent wrapping issues!\n-\t\t\t\tPS1=\"$ps1pc_start (\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n+\t\t\t\tgitstring=\"\\[$branch_color\\]$branchstring\\[$c_clear\\]\"\n \n \t\t\t\tif [ -n \"$w$i$s$u$r$p\" ]; then\n-\t\t\t\t\tPS1=\"$PS1 \"\n+\t\t\t\t\tgitstring=\"$gitstring \"\t\t\t\t\t\n \t\t\t\tfi\n \t\t\t\tif [ \"$w\" = \"*\" ]; then\n-\t\t\t\t\tPS1=\"$PS1\\[$bad_color\\]$w\"\n+\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n \t\t\t\tfi\n \t\t\t\tif [ -n \"$i\" ]; then\n-\t\t\t\t\tPS1=\"$PS1\\[$ok_color\\]$i\"\n+\t\t\t\t\tgitstring=\"$gitstring\\[$ok_color\\]$i\"\n \t\t\t\tfi\n \t\t\t\tif [ -n \"$s\" ]; then\n-\t\t\t\t\tPS1=\"$PS1\\[$flags_color\\]$s\"\n+\t\t\t\t\tgitstring=\"$gitstring\\[$flags_color\\]$s\"\n \t\t\t\tfi\n \t\t\t\tif [ -n \"$u\" ]; then\n-\t\t\t\t\tPS1=\"$PS1\\[$bad_color\\]$u\"\n+\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$u\"\n \t\t\t\tfi\n-\t\t\t\tPS1=\"$PS1\\[$c_clear\\]$r$p)$ps1pc_end\"\n+\t\t\t\tgitstring=\"$gitstring\\[$c_clear\\]$r$p\"\n \t\t\telse\n-\t\t\t\tPS1=\"$ps1pc_start ($c${b##refs/heads/}${f:+ $f}$r$p)$ps1pc_end\"\n+\t\t\t\tgitstring=\"$c${b##refs/heads/}${f:+ $f}$r$p\"\n \t\t\tfi\n+\t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n+\t\t\tPS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n \t\telse\n \t\t\t# NO color option unless in PROMPT_COMMAND mode\n \t\t\tprintf -- \"$printf_format\" \"$c${b##refs/heads/}${f:+ $f}$r$p\"\n-- \n1.7.9.5\n\nPS, I was surprised that this worked, because I was under the impression that the \\[ \\] special characters needed to be put in PS1 directly. This is apparently not exactly the case, but I'm now more confused than before ;-)\n"},{"id":"205503","messageId":"7vmwx0oavn.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"20121226191505.GA29210@simaj.xs4all.nl","subject":"Re: [PATCH] make __git_ps1 accept a third parameter in pcmode","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-26T19:45:48Z","receivedAt":"2012-12-26T19:45:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n\n> The optional third parameter when __git_ps1 is used in\n> PROMPT_COMMAND mode as format string for printf to further\n> customize the way the git status string is embedded in the\n> user's PS1 prompt.\n>\n> Signed-off-by: Simon Oosthoek <s.oosthoek@xs4all.nl>\n> ---\n\nThanks.\n\nIf we do not care about the existing users (and in this case,\nbecause PROMPT_COMMAND mode is in no released version, we could\ndeclare there is no existing user), another and simpler approach is\nto just drop \" (\" and \")\" altogether and have the user give these as\npart of the pre/post strings.\n\nOr we could go the other way and drop \"pre/post\" strings, making\nthem part of the printf_format string.  Perhaps that might be a\nbetter interface in the longer term.  Then people can use the same\n\"<pre>%s<post>\" format string and do either of these:\n\n\tPS1=$(__git_ps1 \"<pre>%s<post>\")\n\tPROMPT_COMMAND='PS1=$(__git_ps1 \"<pre>%s<post>\")'\n\nwithout __git_ps1 having a special \"prompt command\" mode, no?\n\nI have a feeling that I am missing something major, though...\n\n>  \t\t\t\tif [ \"$w\" = \"*\" ]; then\n> -\t\t\t\t\tPS1=\"$PS1\\[$bad_color\\]$w\"\n> +\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n>  \t\t\t\tfi\n\nEvery time I looked at this line, I wondered why '*' state is\n\"bad\".  Does a user go into any \"bad\" state by having a dirty\nworking tree?  Same for untracked ($u) and detached.  These are all\nperfectly normal part of a workflow, so while choice of red may be\nfine to attract attention, calling it \"bad\" sounds misguided.\n"},{"id":"205505","messageId":"20121226201944.GA15039@xs4all.nl","threadId":"32226","inReplyTo":"7vmwx0oavn.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] make __git_ps1 accept a third parameter in pcmode","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-12-26T20:19:44Z","receivedAt":"2012-12-26T20:19:44Z","isPatch":true,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"* Junio C Hamano <gitster@pobox.com> [2012-12-26 11:45:48 -0800]:\n\n> Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n> \n> > The optional third parameter when __git_ps1 is used in\n> > PROMPT_COMMAND mode as format string for printf to further\n> > customize the way the git status string is embedded in the\n> > user's PS1 prompt.\n> >\n> > Signed-off-by: Simon Oosthoek <s.oosthoek@xs4all.nl>\n> > ---\n> \n> Thanks.\n> \n> If we do not care about the existing users (and in this case,\n> because PROMPT_COMMAND mode is in no released version, we could\n> declare there is no existing user), another and simpler approach is\n> to just drop \" (\" and \")\" altogether and have the user give these as\n> part of the pre/post strings.\n> \n\nThe problem with doing it in pre-post is when inside non-git directories. You want to avoid any gitstring output, including the brackets, when not inside a repository.\n\nDoing it all in the third parameter is perhaps a better approach, but then it becomes mandatory instead of optional.\n\n> Or we could go the other way and drop \"pre/post\" strings, making\n> them part of the printf_format string.  Perhaps that might be a\n> better interface in the longer term.  Then people can use the same\n> \"<pre>%s<post>\" format string and do either of these:\n> \n> \tPS1=$(__git_ps1 \"<pre>%s<post>\")\n> \tPROMPT_COMMAND='PS1=$(__git_ps1 \"<pre>%s<post>\")'\n> \n> without __git_ps1 having a special \"prompt command\" mode, no?\n\nBut how to determine which mode to use?\nIn pcmode, you must set the PS1, in command-subsitute mode, you must print a formatted gitstring.\n\n> \n> I have a feeling that I am missing something major, though...\n\nI think the fundamentally different way of setting the PS1 between the two modes is very confusing. Which is why I originally made a different function (with duplicated code) for both modes.\n\n\n> \n> >  \t\t\t\tif [ \"$w\" = \"*\" ]; then\n> > -\t\t\t\t\tPS1=\"$PS1\\[$bad_color\\]$w\"\n> > +\t\t\t\t\tgitstring=\"$gitstring\\[$bad_color\\]$w\"\n> >  \t\t\t\tfi\n> \n> Every time I looked at this line, I wondered why '*' state is\n> \"bad\".  Does a user go into any \"bad\" state by having a dirty\n> working tree?  Same for untracked ($u) and detached.  These are all\n> perfectly normal part of a workflow, so while choice of red may be\n> fine to attract attention, calling it \"bad\" sounds misguided.\n\n\nWell, I'm most often a really casual user of git and to make this function work the way I want to, I found out by trial-and-error that this was a way to test whether it's time to colour the string red or green ;-)\n\nI'm very open to better ways to determine the colour modes. Anyway, the colours are now more or less the same as what git itself uses when printing the status with colour hints in git status.\n\nCheers\n\nSimon\n"},{"id":"205507","messageId":"7vfw2so8q3.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"20121226201944.GA15039@xs4all.nl","subject":"Re: [PATCH] make __git_ps1 accept a third parameter in pcmode","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-26T20:32:20Z","receivedAt":"2012-12-26T20:32:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n\n> The problem with doing it in pre-post is when inside non-git\n> directories. You want to avoid any gitstring output, including the\n> brackets, when not inside a repository.\n\nAh, Ok, that is probably what I missed.\n\n>> Or we could go the other way and drop \"pre/post\" strings, making\n>> them part of the printf_format string.  Perhaps that might be a\n>> better interface in the longer term.  Then people can use the same\n>> \"<pre>%s<post>\" format string and do either of these:\n>> \n>> \tPS1=$(__git_ps1 \"<pre>%s<post>\")\n>> \tPROMPT_COMMAND='PS1=$(__git_ps1 \"<pre>%s<post>\")'\n>> \n>> without __git_ps1 having a special \"prompt command\" mode, no?\n>\n> But how to determine which mode to use?\n> In pcmode, you must set the PS1, in command-subsitute mode, you must print a formatted gitstring.\n\nThe point of the above two was that __git_ps1 does not have to set\nPS1 as long as the insn says user to use PROMPT_COMMAND that sets\nPS1 himself, exactly as illustrated above.  In other words, replace\nthe last PS1=...  in the \"prompt command\" mode with an echo or\nsomething and make the user responsible for assigning it to PS1 in\nhis PROMPT_COMMAND.\n\nOr put it in another way, I was hoping that we can do without adding\nthe prompt command mode---if there is no two modes, there is no need\nto switch between them.\n\nBut as I said, there probably is a reason why that approach does not\nwork, that is why I said...\n\n>> I have a feeling that I am missing something major, though...\n"},{"id":"205509","messageId":"7v7go4o88v.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"20121226201944.GA15039@xs4all.nl","subject":"Re: [PATCH] make __git_ps1 accept a third parameter in pcmode","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-26T20:42:40Z","receivedAt":"2012-12-26T20:42:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Oosthoek <s.oosthoek@xs4all.nl> writes:\n\n>> Every time I looked at this line, I wondered why '*' state is\n>> \"bad\".  Does a user go into any \"bad\" state by having a dirty\n>> working tree?  Same for untracked ($u) and detached.  These are all\n>> perfectly normal part of a workflow, so while choice of red may be\n>> fine to attract attention, calling it \"bad\" sounds misguided.\n>\n> Well, I'm most often a really casual user of git and to make this\n> function work the way I want to, I found out by trial-and-error\n> that this was a way to test whether it's time to colour the string\n> red or green ;-)\n>\n> I'm very open to better ways to determine the colour\n> modes. Anyway, the colours are now more or less the same as what\n> git itself uses when printing the status with colour hints in git\n> status.\n\nOh, I am not opposed to the choice of colors; something that wants\nan attention from the user may be better in red.\n\nI was merely commenting on the choice of the variable name, the user\nof word \"bad\" as if the conditions that use this color were \"bad\" in\nsome way.\n"},{"id":"205510","messageId":"7v38yso7om.fsf@alter.siamese.dyndns.org","threadId":"32226","inReplyTo":"7vfw2so8q3.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] make __git_ps1 accept a third parameter in pcmode","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-26T20:54:49Z","receivedAt":"2012-12-26T20:54:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> But as I said, there probably is a reason why that approach does not\n> work, that is why I said...\n>\n>>> I have a feeling that I am missing something major, though...\n\nIn any case, this was more like \"if we were doing this from scratch\"\nconversation.\n\nI think PROMPT_COMMAND mode that takes <pre> and <post> string has\nbeen advertised throughout the pre-release freeze, which is long\nenough in Git timescale to avoid backward incompatibility, so we are\nalready stuck with the function in two modes even if what I said in\nthe previous message (i.e. \"why not just one mode\") worked.\n\nI am considering to fast-track the \"optional third parameter\" patch\nto the 1.8.1 final, so that we can have the same degree of\ncustomizability in both modes.\n\nThanks.\n"},{"id":"205512","messageId":"20121226210324.GA20704@xs4all.nl","threadId":"32226","inReplyTo":"7vfw2so8q3.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] make __git_ps1 accept a third parameter in pcmode","fromName":"Simon Oosthoek","fromEmail":"s.oosthoek@xs4all.nl","sentAt":"2012-12-26T21:03:24Z","receivedAt":"2012-12-26T21:03:24Z","isPatch":true,"sender":{"key":"s.oosthoek@xs4all.nl","avatar":"https://avatars.githubusercontent.com/u/11677720?v=4"},"body":"* Junio C Hamano <gitster@pobox.com> [2012-12-26 12:32:20 -0800]:\n> The point of the above two was that __git_ps1 does not have to set\n> PS1 as long as the insn says user to use PROMPT_COMMAND that sets\n> PS1 himself, exactly as illustrated above.  In other words, replace\n> the last PS1=...  in the \"prompt command\" mode with an echo or\n> something and make the user responsible for assigning it to PS1 in\n> his PROMPT_COMMAND.\n> \n> Or put it in another way, I was hoping that we can do without adding\n> the prompt command mode---if there is no two modes, there is no need\n> to switch between them.\n> \n> But as I said, there probably is a reason why that approach does not\n> work, that is why I said...\n> \n\nThe only reason to my knowledge is that bash's handling of zero-length strings, like terminal colour commands, is producing a PS1 that outputs less visible characters than bash thinks and thus bash makes mistakes when wrapping the commandline. The way to prevent that is to use \\[ and \\] around those and that doesn't seem to work from a string produced from command-substitution. (BTW, the colours come through just fine, just the \\[ and \\] don't)\n\nAnother approach could be to split up the functionality and have a few support functions to set various variables (corresponding with the gitstring features, like *%+ characters and colour hints). These variables could then be used by a custom PROMPT_COMMAND function or a command substitution function to produce a gitstring. I suppose that would mean a complete rewrite or very close to it ;-)\n\n/Simon\n"}]}