{"thread":{"id":"34744","subject":"[PATCH 3/3] Revert \"bash prompt: avoid command substitution when finalizing gitstring\"","startedAt":"2013-08-21T20:49:31Z","lastAt":"2013-08-22T01:39:03Z","messageCount":10,"participants":["Brandon Casey","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"225640","messageId":"1377118173-23405-1-git-send-email-bcasey@nvidia.com","threadId":"34744","inReplyTo":null,"subject":"[PATCH 1/3] git-completion.bash: use correct Bash/Zsh array length syntax","fromName":"Brandon Casey","fromEmail":"bcasey@nvidia.com","sentAt":"2013-08-21T20:49:31Z","receivedAt":"2013-08-21T20:49:31Z","isPatch":true,"sender":{"key":"bcasey@nvidia.com","avatar":null},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nThe syntax for retrieving the number of elements in an array is:\n\n   ${#name[@]}\n\nSigned-off-by: Brandon Casey <drafnel@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 5da920e..e1b7313 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2580,7 +2580,7 @@ if [[ -n ${ZSH_VERSION-} ]]; then\n \t\t\t\t--*=*|*.) ;;\n \t\t\t\t*) c=\"$c \" ;;\n \t\t\t\tesac\n-\t\t\t\tarray[$#array+1]=\"$c\"\n+\t\t\t\tarray[${#array[@]}+1]=\"$c\"\n \t\t\tdone\n \t\t\tcompset -P '*[=:]'\n \t\t\tcompadd -Q -S '' -p \"${2-}\" -a -- array && _ret=0\n-- \n1.8.4.rc0.2.g6cf5c31\n\n\n-----------------------------------------------------------------------------------\nThis email message is for the sole use of the intended recipient(s) and may contain\nconfidential information.  Any unauthorized review, use, disclosure or distribution\nis prohibited.  If you are not the intended recipient, please contact the sender by\nreply email and destroy all copies of the original message.\n-----------------------------------------------------------------------------------\n"},{"id":"225641","messageId":"1377118173-23405-2-git-send-email-bcasey@nvidia.com","threadId":"34744","inReplyTo":"1377118173-23405-1-git-send-email-bcasey@nvidia.com","subject":"[PATCH 2/3] t9902-completion.sh: old Bash still does not support array+=('') notation","fromName":"Brandon Casey","fromEmail":"bcasey@nvidia.com","sentAt":"2013-08-21T20:49:32Z","receivedAt":"2013-08-21T20:49:32Z","isPatch":true,"sender":{"key":"bcasey@nvidia.com","avatar":null},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nOld Bash (3.0) which is distributed with RHEL 4.X and other ancient\nplatforms that are still in wide use, does not understand the\narray+=() notation.  Let's use an explicit assignment to the new array\nelement which works everywhere, like:\n\n   array[${#array[@]}+1]=''\n\nThe right-hand side '' is not strictly necessary, but in this case\nI think it is more clear.\n\nSigned-off-by: Brandon Casey <drafnel@gmail.com>\n---\n t/t9902-completion.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 272a071..2d4beb5 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -69,7 +69,7 @@ run_completion ()\n \tlocal -a COMPREPLY _words\n \tlocal _cword\n \t_words=( $1 )\n-\ttest \"${1: -1}\" = ' ' && _words+=('')\n+\ttest \"${1: -1}\" = ' ' && _words[${#_words[@]}+1]=''\n \t(( _cword = ${#_words[@]} - 1 ))\n \t__git_wrap__git_main && print_comp\n }\n-- \n1.8.4.rc0.2.g6cf5c31\n\n\n-----------------------------------------------------------------------------------\nThis email message is for the sole use of the intended recipient(s) and may contain\nconfidential information.  Any unauthorized review, use, disclosure or distribution\nis prohibited.  If you are not the intended recipient, please contact the sender by\nreply email and destroy all copies of the original message.\n-----------------------------------------------------------------------------------\n"},{"id":"225639","messageId":"1377118173-23405-3-git-send-email-bcasey@nvidia.com","threadId":"34744","inReplyTo":"1377118173-23405-1-git-send-email-bcasey@nvidia.com","subject":"[PATCH 3/3] Revert \"bash prompt: avoid command substitution when finalizing gitstring\"","fromName":"Brandon Casey","fromEmail":"bcasey@nvidia.com","sentAt":"2013-08-21T20:49:33Z","receivedAt":"2013-08-21T20:49:33Z","isPatch":true,"sender":{"key":"bcasey@nvidia.com","avatar":null},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nThis reverts commit 69a8141a5d81925b7e08cb228535e9ea4a7a02e3.\n\nOld Bash (3.0) which is distributed with RHEL 4.X and other ancient\nplatforms that are still in wide use, does not have a printf that\nsupports -v.  Let's revert this patch and go back to using printf\nin the traditional way.\n\nSigned-off-by: Brandon Casey <drafnel@gmail.com>\n---\n contrib/completion/git-prompt.sh | 6 +-----\n 1 file changed, 1 insertion(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex a81ef5a..7698ec4 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -433,11 +433,7 @@ __git_ps1 ()\n \tlocal gitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n \n \tif [ $pcmode = yes ]; then\n-\t\tif [[ -n ${ZSH_VERSION-} ]]; then\n-\t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n-\t\telse\n-\t\t\tprintf -v gitstring -- \"$printf_format\" \"$gitstring\"\n-\t\tfi\n+\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n \t\tPS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n \telse\n \t\tprintf -- \"$printf_format\" \"$gitstring\"\n-- \n1.8.4.rc0.2.g6cf5c31\n\n\n-----------------------------------------------------------------------------------\nThis email message is for the sole use of the intended recipient(s) and may contain\nconfidential information.  Any unauthorized review, use, disclosure or distribution\nis prohibited.  If you are not the intended recipient, please contact the sender by\nreply email and destroy all copies of the original message.\n-----------------------------------------------------------------------------------\n"},{"id":"225650","messageId":"xmqq7gfeu35g.fsf@gitster.dls.corp.google.com","threadId":"34744","inReplyTo":"1377118173-23405-3-git-send-email-bcasey@nvidia.com","subject":"Re: [PATCH 3/3] Revert \"bash prompt: avoid command substitution when finalizing gitstring\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-21T21:47:55Z","receivedAt":"2013-08-21T21:47:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brandon Casey <bcasey@nvidia.com> writes:\n\n> From: Brandon Casey <drafnel@gmail.com>\n>\n> This reverts commit 69a8141a5d81925b7e08cb228535e9ea4a7a02e3.\n>\n> Old Bash (3.0) which is distributed with RHEL 4.X and other ancient\n> platforms that are still in wide use, does not have a printf that\n> supports -v.  Let's revert this patch and go back to using printf\n> in the traditional way.\n>\n> Signed-off-by: Brandon Casey <drafnel@gmail.com>\n> ---\n\nIs this something you can detect at load-time once, store the result\nin a private variable and then switch on it at runtime, something\nalong the lines of...\n\n\n\t# on load...\n\tprintf -v __git_printf_supports_v -- \"%s\" yes >/dev/null 2>&1\n        \n\t...\n\n\tif test \"${__git_printf_supports_v}\" = yes\n        then\n\t\tprintf -v gitstring -- \"$printf_format\" \"$gitstring\"\n\telse\n\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n        fi\n\n\n>  contrib/completion/git-prompt.sh | 6 +-----\n>  1 file changed, 1 insertion(+), 5 deletions(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index a81ef5a..7698ec4 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -433,11 +433,7 @@ __git_ps1 ()\n>  \tlocal gitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n>  \n>  \tif [ $pcmode = yes ]; then\n> -\t\tif [[ -n ${ZSH_VERSION-} ]]; then\n> -\t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n> -\t\telse\n> -\t\t\tprintf -v gitstring -- \"$printf_format\" \"$gitstring\"\n> -\t\tfi\n> +\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n>  \t\tPS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n>  \telse\n>  \t\tprintf -- \"$printf_format\" \"$gitstring\"\n"},{"id":"225653","messageId":"CA+sFfMc0BPo8pSLngi=bAWxYNT8xKFEOo77z3a12q+-Sq4qiiA@mail.gmail.com","threadId":"34744","inReplyTo":"xmqq7gfeu35g.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 3/3] Revert \"bash prompt: avoid command substitution when finalizing gitstring\"","fromName":"Brandon Casey","fromEmail":"drafnel@gmail.com","sentAt":"2013-08-21T22:08:25Z","receivedAt":"2013-08-21T22:08:25Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"On Wed, Aug 21, 2013 at 2:47 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Brandon Casey <bcasey@nvidia.com> writes:\n>\n>> From: Brandon Casey <drafnel@gmail.com>\n>>\n>> This reverts commit 69a8141a5d81925b7e08cb228535e9ea4a7a02e3.\n>>\n>> Old Bash (3.0) which is distributed with RHEL 4.X and other ancient\n>> platforms that are still in wide use, does not have a printf that\n>> supports -v.  Let's revert this patch and go back to using printf\n>> in the traditional way.\n>>\n>> Signed-off-by: Brandon Casey <drafnel@gmail.com>\n>> ---\n>\n> Is this something you can detect at load-time once, store the result\n> in a private variable and then switch on it at runtime, something\n> along the lines of...\n>\n>\n>         # on load...\n>         printf -v __git_printf_supports_v -- \"%s\" yes >/dev/null 2>&1\n>\n>         ...\n>\n>         if test \"${__git_printf_supports_v}\" = yes\n>         then\n>                 printf -v gitstring -- \"$printf_format\" \"$gitstring\"\n>         else\n>                 gitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n>         fi\n\nYes, that appears to work.\n\n-Brandon\n\n\n>>  contrib/completion/git-prompt.sh | 6 +-----\n>>  1 file changed, 1 insertion(+), 5 deletions(-)\n>>\n>> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n>> index a81ef5a..7698ec4 100644\n>> --- a/contrib/completion/git-prompt.sh\n>> +++ b/contrib/completion/git-prompt.sh\n>> @@ -433,11 +433,7 @@ __git_ps1 ()\n>>       local gitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n>>\n>>       if [ $pcmode = yes ]; then\n>> -             if [[ -n ${ZSH_VERSION-} ]]; then\n>> -                     gitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n>> -             else\n>> -                     printf -v gitstring -- \"$printf_format\" \"$gitstring\"\n>> -             fi\n>> +             gitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n>>               PS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n>>       else\n>>               printf -- \"$printf_format\" \"$gitstring\"\n"},{"id":"225665","messageId":"xmqq7gfesheu.fsf@gitster.dls.corp.google.com","threadId":"34744","inReplyTo":"CA+sFfMc0BPo8pSLngi=bAWxYNT8xKFEOo77z3a12q+-Sq4qiiA@mail.gmail.com","subject":"Re: [PATCH 3/3] Revert \"bash prompt: avoid command substitution when finalizing gitstring\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-22T00:22:49Z","receivedAt":"2013-08-22T00:22:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brandon Casey <drafnel@gmail.com> writes:\n\n> On Wed, Aug 21, 2013 at 2:47 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Brandon Casey <bcasey@nvidia.com> writes:\n>>\n>>> From: Brandon Casey <drafnel@gmail.com>\n>>>\n>>> This reverts commit 69a8141a5d81925b7e08cb228535e9ea4a7a02e3.\n>>>\n>>> Old Bash (3.0) which is distributed with RHEL 4.X and other ancient\n>>> platforms that are still in wide use, does not have a printf that\n>>> supports -v.  Let's revert this patch and go back to using printf\n>>> in the traditional way.\n>>>\n>>> Signed-off-by: Brandon Casey <drafnel@gmail.com>\n>>> ---\n>>\n>> Is this something you can detect at load-time once, store the result\n>> in a private variable and then switch on it at runtime, something\n>> along the lines of...\n>>\n>>\n>>         # on load...\n>>         printf -v __git_printf_supports_v -- \"%s\" yes >/dev/null 2>&1\n>>\n>>         ...\n>>\n>>         if test \"${__git_printf_supports_v}\" = yes\n>>         then\n>>                 printf -v gitstring -- \"$printf_format\" \"$gitstring\"\n>>         else\n>>                 gitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n>>         fi\n>\n> Yes, that appears to work.\n\nA real patch needs to be a bit more careful, though.  The variable\nneeds to be cleared before all of the above, and the testing would\nwant to consider that the variable may not be set (i.e. use\n\"${var-}\" when checking).\n\nThanks.\n\n> -Brandon\n>\n>\n>>>  contrib/completion/git-prompt.sh | 6 +-----\n>>>  1 file changed, 1 insertion(+), 5 deletions(-)\n>>>\n>>> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n>>> index a81ef5a..7698ec4 100644\n>>> --- a/contrib/completion/git-prompt.sh\n>>> +++ b/contrib/completion/git-prompt.sh\n>>> @@ -433,11 +433,7 @@ __git_ps1 ()\n>>>       local gitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n>>>\n>>>       if [ $pcmode = yes ]; then\n>>> -             if [[ -n ${ZSH_VERSION-} ]]; then\n>>> -                     gitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n>>> -             else\n>>> -                     printf -v gitstring -- \"$printf_format\" \"$gitstring\"\n>>> -             fi\n>>> +             gitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n>>>               PS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n>>>       else\n>>>               printf -- \"$printf_format\" \"$gitstring\"\n"},{"id":"225666","messageId":"CA+sFfMfa422PF1inOOeTBRE7HRqL5zwCJNagx9Ya0i_LbpwQcg@mail.gmail.com","threadId":"34744","inReplyTo":"xmqq7gfesheu.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 3/3] Revert \"bash prompt: avoid command substitution when finalizing gitstring\"","fromName":"Brandon Casey","fromEmail":"drafnel@gmail.com","sentAt":"2013-08-22T00:33:05Z","receivedAt":"2013-08-22T00:33:05Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"On Wed, Aug 21, 2013 at 5:22 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Brandon Casey <drafnel@gmail.com> writes:\n>\n>> On Wed, Aug 21, 2013 at 2:47 PM, Junio C Hamano <gitster@pobox.com> wrote:\n\n>>>         # on load...\n>>>         printf -v __git_printf_supports_v -- \"%s\" yes >/dev/null 2>&1\n>>>\n>>>         ...\n>>>\n>>>         if test \"${__git_printf_supports_v}\" = yes\n>>>         then\n>>>                 printf -v gitstring -- \"$printf_format\" \"$gitstring\"\n>>>         else\n>>>                 gitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n>>>         fi\n>>\n>> Yes, that appears to work.\n>\n> A real patch needs to be a bit more careful, though.  The variable\n> needs to be cleared before all of the above,\n\nAgreed.\n\n> and the testing would\n> want to consider that the variable may not be set (i.e. use\n> \"${var-}\" when checking).\n\nWhy is \"${var-}\" necessary?  Wouldn't that be equivalent to \"${var}\"\nor \"$var\"?  We obviously wouldn't want to do 'if test $var = yes', but\nI would have thought it was sufficient to wrap the variable\ndereference in quotes as your original did.\n\n-Brandon\n"},{"id":"225668","messageId":"1377134242-15012-1-git-send-email-bcasey@nvidia.com","threadId":"34744","inReplyTo":"CA+sFfMfa422PF1inOOeTBRE7HRqL5zwCJNagx9Ya0i_LbpwQcg@mail.gmail.com","subject":"[PATCH] contrib/git-prompt.sh: handle missing 'printf -v' more gracefully","fromName":"Brandon Casey","fromEmail":"bcasey@nvidia.com","sentAt":"2013-08-22T01:17:22Z","receivedAt":"2013-08-22T01:17:22Z","isPatch":true,"sender":{"key":"bcasey@nvidia.com","avatar":null},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nOld Bash (3.0) which is distributed with RHEL 4.X and other ancient\nplatforms that are still in wide use, do not have a printf that\nsupports -v.  Neither does Zsh (which is already handled in the code).\n\nAs suggested by Junio, let's test whether printf supports the -v\noption and store the result.  Then later, we can use it to\ndetermine whether 'printf -v' can be used, or whether printf\nmust be called in a subshell.\n\nSigned-off-by: Brandon Casey <drafnel@gmail.com>\n---\n\nThis replaces [PATCH 3/3] Revert \"bash prompt: avoid command substitution\nwhen finalizing gitstring\".\n\nThis may or may not need to be updated to use \"${var-}\" depending on\nyour response to my other email, but this seems sufficient.\n\n-Brandon\n\n contrib/completion/git-prompt.sh | 10 +++++++---\n 1 file changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex a81ef5a..639888a 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,10 @@\n # the colored output of \"git status -sb\" and are available only when\n # using __git_ps1 for PROMPT_COMMAND or precmd.\n \n+# check whether printf supports -v\n+__git_printf_supports_v=\n+printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1\n+\n # stores the divergence from upstream in $p\n # used by GIT_PS1_SHOWUPSTREAM\n __git_ps1_show_upstream ()\n@@ -433,10 +437,10 @@ __git_ps1 ()\n \tlocal gitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n \n \tif [ $pcmode = yes ]; then\n-\t\tif [[ -n ${ZSH_VERSION-} ]]; then\n-\t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n-\t\telse\n+\t\tif test \"$__git_printf_supports_v\" = yes; then\n \t\t\tprintf -v gitstring -- \"$printf_format\" \"$gitstring\"\n+\t\telse\n+\t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n \t\tfi\n \t\tPS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n \telse\n-- \n1.8.4.rc0.2.g6cf5c31\n\n\n-----------------------------------------------------------------------------------\nThis email message is for the sole use of the intended recipient(s) and may contain\nconfidential information.  Any unauthorized review, use, disclosure or distribution\nis prohibited.  If you are not the intended recipient, please contact the sender by\nreply email and destroy all copies of the original message.\n-----------------------------------------------------------------------------------\n"},{"id":"225670","messageId":"xmqq38q2sefa.fsf@gitster.dls.corp.google.com","threadId":"34744","inReplyTo":"CA+sFfMfa422PF1inOOeTBRE7HRqL5zwCJNagx9Ya0i_LbpwQcg@mail.gmail.com","subject":"Re: [PATCH 3/3] Revert \"bash prompt: avoid command substitution when finalizing gitstring\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-08-22T01:27:21Z","receivedAt":"2013-08-22T01:27:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brandon Casey <drafnel@gmail.com> writes:\n\n> Why is \"${var-}\" necessary?  Wouldn't that be equivalent to \"${var}\"\n> or \"$var\"?\n\nset -u\n"},{"id":"225671","messageId":"1377135543-19053-1-git-send-email-bcasey@nvidia.com","threadId":"34744","inReplyTo":"1377134242-15012-1-git-send-email-bcasey@nvidia.com","subject":"[PATCH] contrib/git-prompt.sh: handle missing 'printf -v' more gracefully","fromName":"Brandon Casey","fromEmail":"bcasey@nvidia.com","sentAt":"2013-08-22T01:39:03Z","receivedAt":"2013-08-22T01:39:03Z","isPatch":true,"sender":{"key":"bcasey@nvidia.com","avatar":null},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nOld Bash (3.0) which is distributed with RHEL 4.X and other ancient\nplatforms that are still in wide use, do not have a printf that\nsupports -v.  Neither does Zsh (which is already handled in the code).\n\nAs suggested by Junio, let's test whether printf supports the -v\noption and store the result.  Then later, we can use it to\ndetermine whether 'printf -v' can be used, or whether printf\nmust be called in a subshell.\n\nSigned-off-by: Brandon Casey <drafnel@gmail.com>\n---\n\n\nOn 8/21/2013 6:27 PM, Junio C Hamano wrote:> Brandon Casey <drafnel@gmail.com> writes:\n>\n>> Why is \"${var-}\" necessary?  Wouldn't that be equivalent to \"${var}\"\n>> or \"$var\"?\n>\n> set -u\n\nAh.  Thanks.  Updated.  Also minor tweak to use [ ] instead of test ...\nto conform with the rest of the script.\n\n-Brandon\n\n\n contrib/completion/git-prompt.sh | 10 +++++++---\n 1 file changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex a81ef5a..ca7fb35 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,10 @@\n # the colored output of \"git status -sb\" and are available only when\n # using __git_ps1 for PROMPT_COMMAND or precmd.\n \n+# check whether printf supports -v\n+__git_printf_supports_v=\n+printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1\n+\n # stores the divergence from upstream in $p\n # used by GIT_PS1_SHOWUPSTREAM\n __git_ps1_show_upstream ()\n@@ -433,10 +437,10 @@ __git_ps1 ()\n \tlocal gitstring=\"$c${b##refs/heads/}${f:+$z$f}$r$p\"\n \n \tif [ $pcmode = yes ]; then\n-\t\tif [[ -n ${ZSH_VERSION-} ]]; then\n-\t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n-\t\telse\n+\t\tif [ \"${__git_printf_supports_v-}\" = yes ]; then\n \t\t\tprintf -v gitstring -- \"$printf_format\" \"$gitstring\"\n+\t\telse\n+\t\t\tgitstring=$(printf -- \"$printf_format\" \"$gitstring\")\n \t\tfi\n \t\tPS1=\"$ps1pc_start$gitstring$ps1pc_end\"\n \telse\n-- \n1.8.4.rc0.2.g6cf5c31\n\n\n-----------------------------------------------------------------------------------\nThis email message is for the sole use of the intended recipient(s) and may contain\nconfidential information.  Any unauthorized review, use, disclosure or distribution\nis prohibited.  If you are not the intended recipient, please contact the sender by\nreply email and destroy all copies of the original message.\n-----------------------------------------------------------------------------------\n"}]}