Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
Simon Oosthoek writes: > This patch for the documentation doesn't seem to be in rc2 of 1.8.1... There wasn't any patch, and after sending "something like this" I forgot about the topic, as usual. > The current tagged 1.8.1-rc2 doesn't yet have your improvement and after > trying to explain it, I think it should be improved even more ;-) I am not sure what "my improvement" you are refering to. Is it only about how the usage appears in the comment? Perhaps like this? I think the straight-forward one should be listed as the primary usage, and the confusing one should be an alternate for advanced users, so 3a/3b have been swapped. contrib/completion/git-prompt.sh | 16 +++- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git i/contrib/completion/git-prompt.sh w/contrib/completion/git-prompt.sh index 00fc099..899eb09 100644 --- i/contrib/completion/git-prompt.sh +++ w/contrib/completion/git-prompt.sh @@ -10,14 +10,20 @@ #1) Copy this file to somewhere (e.g. ~/.git-prompt.sh). #2) Add the following line to your .bashrc/.zshrc: #source ~/.git-prompt.sh -#3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1 -#To customize the prompt, provide start/end arguments -#PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' -#3b) Alternatively change your PS1 to call __git_ps1 as +#3a) Change your PS1 to call __git_ps1 as #command-substitution: #Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' #ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ ' -#the optional argument will be used as format string +#the optional argument will be used as format string. +#3b) Alternatively, if you are using bash, __git_ps1 can be +#used for PROMPT_COMMAND with two parameters, and +#, which are strings you would put in $PS1 before +#and after the status string generated by the git-prompt +#machinery. e.g. +# PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' +#will show username, at-sign, host, colon, cwd, then +#various status string, followed by dollar and SP, as +#your prompt. # # The argument to __git_ps1 will be displayed only if you are currently # in a git repository. The %s token will be the name of the current -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
Junio C Hamano writes: > Perhaps like this? OK, this time with a log message. -- >8 -- Subject: [PATCH] git-prompt.sh: update PROMPT_COMMAND documentation The description of __git_ps1 function operating in two-arg mode was not very clear. It said "set PROMPT_COMMAND=__git_ps1" which is not the right usage for this mode, followed by "To customize the prompt, do this", giving a false impression that those who do not want to customize it can get away with no-arg form, which was incorrect. Make it clear that this mode always takes two arguments, pre and post, with an example. The straight-forward one should be listed as the primary usage, and the confusing one should be an alternate for advanced users. Swap the order of these two. Signed-off-by: Junio C Hamano --- contrib/completion/git-prompt.sh | 16 +++- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index a8b53ba..9b074e1 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -10,14 +10,20 @@ #1) Copy this file to somewhere (e.g. ~/.git-prompt.sh). #2) Add the following line to your .bashrc/.zshrc: #source ~/.git-prompt.sh -#3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1 -#To customize the prompt, provide start/end arguments -#PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' -#3b) Alternatively change your PS1 to call __git_ps1 as +#3a) Change your PS1 to call __git_ps1 as #command-substitution: #Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' #ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ ' -#the optional argument will be used as format string +#the optional argument will be used as format string. +#3b) Alternatively, if you are using bash, __git_ps1 can be +#used for PROMPT_COMMAND with two parameters, and +#, which are strings you would put in $PS1 before +#and after the status string generated by the git-prompt +#machinery. e.g. +# PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' +#will show username, at-sign, host, colon, cwd, then +#various status string, followed by dollar and SP, as +#your prompt. # # The argument to __git_ps1 will be displayed only if you are currently # in a git repository. The %s token will be the name of the current -- 1.8.1.rc1.128.gd8d1528 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
Hi Junio This removes most of the ambiguities :-) Ack from me! I still have some minor nits, but I'll leave that for another time when I'm less busy. BTW, 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! At 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. Cheers Simon * Junio C Hamano [2012-12-11 16:03:36 -0800]: > Junio C Hamano writes: > > > Perhaps like this? > > OK, this time with a log message. > > -- >8 -- > Subject: [PATCH] git-prompt.sh: update PROMPT_COMMAND documentation > > The description of __git_ps1 function operating in two-arg mode was > not very clear. It said "set PROMPT_COMMAND=__git_ps1" which is not > the right usage for this mode, followed by "To customize the prompt, > do this", giving a false impression that those who do not want to > customize it can get away with no-arg form, which was incorrect. > > Make it clear that this mode always takes two arguments, pre and > post, with an example. > > The straight-forward one should be listed as the primary usage, and > the confusing one should be an alternate for advanced users. Swap > the order of these two. > > Signed-off-by: Junio C Hamano > --- > contrib/completion/git-prompt.sh | 16 +++- > 1 file changed, 11 insertions(+), 5 deletions(-) > > diff --git a/contrib/completion/git-prompt.sh > b/contrib/completion/git-prompt.sh > index a8b53ba..9b074e1 100644 > --- a/contrib/completion/git-prompt.sh > +++ b/contrib/completion/git-prompt.sh > @@ -10,14 +10,20 @@ > #1) Copy this file to somewhere (e.g. ~/.git-prompt.sh). > #2) Add the following line to your .bashrc/.zshrc: > #source ~/.git-prompt.sh > -#3a) In ~/.bashrc set PROMPT_COMMAND=__git_ps1 > -#To customize the prompt, provide start/end arguments > -#PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' > -#3b) Alternatively change your PS1 to call __git_ps1 as > +#3a) Change your PS1 to call __git_ps1 as > #command-substitution: > #Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' > #ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ ' > -#the optional argument will be used as format string > +#the optional argument will be used as format string. > +#3b) Alternatively, if you are using bash, __git_ps1 can be > +#used for PROMPT_COMMAND with two parameters, and > +#, which are strings you would put in $PS1 before > +#and after the status string generated by the git-prompt > +#machinery. e.g. > +# PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' > +#will show username, at-sign, host, colon, cwd, then > +#various status string, followed by dollar and SP, as > +#your prompt. > # > # The argument to __git_ps1 will be displayed only if you are currently > # in a git repository. The %s token will be the name of the current > -- > 1.8.1.rc1.128.gd8d1528 > -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
Simon Oosthoek writes: > This removes most of the ambiguities :-) > Ack from me! OK, as this is a low-impact finishing touch for a new feature, I'll fast-track this to 'master' before the final release. Thanks. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
On 12/12/12 18:50, Junio C Hamano wrote: > Simon Oosthoek writes: > >> This removes most of the ambiguities :-) >> Ack from me! > > OK, as this is a low-impact finishing touch for a new feature, I'll > fast-track this to 'master' before the final release. > Ok, wonderful! BTW, I tried the thing I mentioned and it was safe to do: PS1='blabla$(__git_ps1 x y)blabla' will not eat your prompt, although I'd recommend putting something useful instead of blabla ;-) Cheers Simon -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
Simon Oosthoek writes: > On 12/12/12 18:50, Junio C Hamano wrote: >> Simon Oosthoek writes: >> >>> This removes most of the ambiguities :-) >>> Ack from me! >> >> OK, as this is a low-impact finishing touch for a new feature, I'll >> fast-track this to 'master' before the final release. >> > > Ok, wonderful! > BTW, I tried the thing I mentioned and it was safe to do: > PS1='blabla$(__git_ps1 x y)blabla' > will not eat your prompt, although I'd recommend putting something > useful instead of blabla ;-) Actually, I deeply regret merging this to 'master'. The original "as a command substitution in PS1" mode, you could add anything around the status string, so I could do: PS1=': \h \W$(__git_ps1 "/%s"); ' to get something like: : hostname dirname/; In the new PROMPT_COMMAND mode, there is always parentheses around the status string (and an SP before the parenthesees) that the user cannot get rid of. This is not a usability regression per-se (if you do not like the extra parentheses, you do not have to use the colored mode), but is something that will make me never use the mode. Can we make it take an optional third parameter so that we could say PROMPT_COMMAND='__git_ps1 ": \h \W" "; " "/%s"' to do the same as what the command substitution mode would have given for PS1=': \h \W$(__git_ps1 "/%s"); ' perhaps? Totally untested, but perhaps along this line. contrib/completion/git-prompt.sh | 24 ++-- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 9b074e1..b2579f4 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -236,9 +236,10 @@ __git_ps1 () local printf_format=' (%s)' case "$#" in - 2) pcmode=yes + 2|3)pcmode=yes ps1pc_start="$1" ps1pc_end="$2" + printf_format="${3:-$printf_format}" ;; 0|1)printf_format="${1:-$printf_format}" ;; @@ -339,6 +340,7 @@ __git_ps1 () local f="$w$i$s$u" if [ $pcmode = yes ]; then + local ps1= if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then local c_red='\e[31m' local c_green='\e[32m' @@ -356,29 +358,31 @@ __git_ps1 () branch_color="$bad_color" fi - # Setting PS1 directly with \[ and \] around colors + # Setting ps1 directly with \[ and \] around colors # is necessary to prevent wrapping issues! - PS1="$ps1pc_start (\[$branch_color\]$branchstring\[$c_clear\]" + ps1="\[$branch_color\]$branchstring\[$c_clear\]" if [ -n "$w$i$s$u$r$p" ]; then - PS1="$PS1 " + ps1="$ps1 " fi if [ "$w" = "*" ]; then - PS1="$PS1\[$bad_color\]$w" + ps1="$ps1\[$bad_color\]$w" fi if [ -n "$i" ]; then - PS1="$PS1\[$ok_color\]$i" + ps1="$ps1\[$ok_color\]$i" fi if [ -n "$s" ]; then - PS1="$PS1\[$flags_color\]$s" + ps1="$ps1\[$flags_color\]$s" fi if [ -n "$u" ]; then - PS1="$PS1\[$bad_color\]$u" + ps1="$ps1\[$bad_color\]$u" fi - PS1="$PS1\[$c_clear\]$r$p)$ps1pc_end" + ps1="$ps1\[$c_clear\]$r$p" else - PS1="$ps1pc_start ($c${b##refs/heads/}${f:+ $f}$r$p)$ps1pc_end" + ps1="$c${b##refs/heads/}${f:+ $f}$r$p" fi + ps1=$(printf -- "$printf_format" "$ps1") + PS1="$ps1pc_start$ps1$ps1pc_end" else # NO color option unless in PROMPT_COMMAND mode printf -- "$printf_format" "$c${b##refs/heads/}${f:+ $f}$r$p" -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
* Junio C Hamano [2012-12-25 23:47:53 -0800]: > Can we make it take an optional third parameter so that we could say > > PROMPT_COMMAND='__git_ps1 ": \h \W" "; " "/%s"' > > to do the same as what the command substitution mode would have > given for > > PS1=': \h \W$(__git_ps1 "/%s"); ' > > perhaps? > > Totally untested, but perhaps along this line. > I tried your patch and (to my surprise, after the first reading) it worked. I've further modified git-prompt.sh to include more usage text and I changed the name of ps1 to gitstring, as it might be confused with PS1 upon casual reading. I'll be sending a format-patch patchmail ASAP... > contrib/completion/git-prompt.sh | 24 ++-- > 1 file changed, 14 insertions(+), 10 deletions(-) > > diff --git a/contrib/completion/git-prompt.sh > b/contrib/completion/git-prompt.sh > index 9b074e1..b2579f4 100644 > --- a/contrib/completion/git-prompt.sh > +++ b/contrib/completion/git-prompt.sh > @@ -236,9 +236,10 @@ __git_ps1 () > local printf_format=' (%s)' > > case "$#" in > - 2) pcmode=yes > + 2|3)pcmode=yes > ps1pc_start="$1" > ps1pc_end="$2" > + printf_format="${3:-$printf_format}" > ;; > 0|1)printf_format="${1:-$printf_format}" > ;; > @@ -339,6 +340,7 @@ __git_ps1 () > > local f="$w$i$s$u" > if [ $pcmode = yes ]; then > + local ps1= > if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then > local c_red='\e[31m' > local c_green='\e[32m' > @@ -356,29 +358,31 @@ __git_ps1 () > branch_color="$bad_color" > fi > > - # Setting PS1 directly with \[ and \] around > colors > + # Setting ps1 directly with \[ and \] around > colors > # is necessary to prevent wrapping issues! > - PS1="$ps1pc_start > (\[$branch_color\]$branchstring\[$c_clear\]" > + ps1="\[$branch_color\]$branchstring\[$c_clear\]" > > if [ -n "$w$i$s$u$r$p" ]; then > - PS1="$PS1 " > + ps1="$ps1 " > > fi > if [ "$w" = "*" ]; then > - PS1="$PS1\[$bad_color\]$w" > + ps1="$ps1\[$bad_color\]$w" > fi > if [ -n "$i" ]; then > - PS1="$PS1\[$ok_color\]$i" > + ps1="$ps1\[$ok_color\]$i" > fi > if [ -n "$s" ]; then > - PS1="$PS1\[$flags_color\]$s" > + ps1="$ps1\[$flags_color\]$s" > fi > if [ -n "$u" ]; then > - PS1="$PS1\[$bad_color\]$u" > + ps1="$ps1\[$bad_color\]$u" > fi > - PS1="$PS1\[$c_clear\]$r$p)$ps1pc_end" > + ps1="$ps1\[$c_clear\]$r$p" > else > - PS1="$ps1pc_start ($c${b##refs/heads/}${f:+ > $f}$r$p)$ps1pc_end" > + ps1="$c${b##refs/heads/}${f:+ $f}$r$p" > fi > + ps1=$(printf -- "$printf_format" "$ps1") > + PS1="$ps1pc_start$ps1$ps1pc_end" > else > # NO color option unless in PROMPT_COMMAND mode > printf -- "$printf_format" "$c${b##refs/heads/}${f:+ > $f}$r$p" /Simon -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
* Piotr Krukowiecki [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 I believe you need to give 2 parameters in order to use it in PROMPT_COMMAND mode. In my .bashrc I have: if [ -f ~/.gitprompt.sh ] then . ~/.gitprompt.sh GIT_PS1_SHOWDIRTYSTATE=true GIT_PS1_SHOWCOLORHINTS=true GIT_PS1_SHOWUNTRACKEDFILES=true PROMPT_COMMAND="__git_ps1 '\u@\[\e[1;34m\]\h\[\e[0m\]:\w' '\\\$ '" fi > (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. Cheers Simon -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
Re-sending mail. On Wed, Nov 28, 2012 at 7:02 PM, Piotr Krukowiecki wrote: > > On Wed, Nov 28, 2012 at 2:20 PM, Simon Oosthoek wrote: >> >> * Piotr Krukowiecki [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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
On 28/11/12 19:02, Piotr Krukowiecki wrote: > 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. > I'm sure, although you're right this documentation is wrong... I guess it must have slipped by when the final changes were made to the code. (The requirement to have 2 arguments for PROMPT_COMMAND mode were one of the last changes before being accepted into the release process.) I've been too busy with other stuff to take another look at this in the meantime. perhaps the point should read like this: #3a) In ~/.bashrc set PROMPT_COMMAND #To customize the prompt, provide start/end arguments #PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' Which would not be confusing at all, I think... > > > 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".. It only works in your specific case, since you're expecting the branch info before the rest of your prompt. The output comes from the part of the code that is meant for substitution mode ;-) Cheers Simon -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
Simon Oosthoek writes: > perhaps the point should read like this: > #3a) In ~/.bashrc set PROMPT_COMMAND > #To customize the prompt, provide start/end arguments > #PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' > > Which would not be confusing at all, I think... It says "to customize", so a user who just wants the default (which does not exist but the comment does not say so) would be left without instruction, no? In $HOME/.bashrc, PROMPT_COMMAND can be set to '__git_ps1 ', where and are strings you would put in $PS1 before and after the status string generated by git-prompt machinery. e.g. PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' or something? -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
On 28/11/12 21:47, Junio C Hamano wrote: > Simon Oosthoek writes: > >> perhaps the point should read like this: >> #3a) In ~/.bashrc set PROMPT_COMMAND >> #To customize the prompt, provide start/end arguments >> #PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' >> >> Which would not be confusing at all, I think... > > It says "to customize", so a user who just wants the default (which > does not exist but the comment does not say so) would be left > without instruction, no? > > In $HOME/.bashrc, PROMPT_COMMAND can be set to > '__git_ps1 ', where and > are strings you would put in $PS1 before and after > the status string generated by git-prompt machinery. > e.g. > PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' > > or something? > Looks better than my suggestion :-) thanks /Simon -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: git-prompt.sh vs leading white space in __git_ps1()::printf_format
Hi Junio This patch for the documentation doesn't seem to be in rc2 of 1.8.1... tonight I was explaining this feature to a small group of people and I pulled the git tree to get the latest code. The current tagged 1.8.1-rc2 doesn't yet have your improvement and after trying to explain it, I think it should be improved even more ;-) I'm sorry to say I don't have the time right now to make a proper patch, but I'll try to expand below... On 28/11/12 21:47, Junio C Hamano wrote: > Simon Oosthoek writes: > >> perhaps the point should read like this: >> #3a) In ~/.bashrc set PROMPT_COMMAND >> #To customize the prompt, provide start/end arguments >> #PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' >> >> Which would not be confusing at all, I think... > > It says "to customize", so a user who just wants the default (which > does not exist but the comment does not say so) would be left > without instruction, no? > > In $HOME/.bashrc, PROMPT_COMMAND can be set to > '__git_ps1 ', where and > are strings you would put in $PS1 before and after > the status string generated by git-prompt machinery. > e.g. > PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' > > or something? > The gist should be that: __git_ps1 can function in two modes; The "traditional" way with command substitution. This mode is activated when the function is provided 0 or 1 arguments. The new way, activated by providing exactly 2 arguments to __git_ps1 is intended for use in the PROMPT_COMMAND way of bash to call a function before writing the prompt. This command can then be (and is in fact) used to set/overwrite the PS1 variable. Only in the PROMPT_COMMAND mode can you get a prompt with colors for the various states of the git tree showing in the prompt. An example for inclusion in the ~/.bashrc file is: -snip- PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' GIT_PS1_SHOWDIRTYSTATE=true GIT_PS1_SHOWCOLORHINTS=true -- It turns out that it can be quite confusing to get your head around this split personality of __git_ps1... I hope you can somehow get this into the next release with some improvement to the docs! Cheers Simon -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html