Re: [PATCH 3/3] Revert "bash prompt: avoid command substitution when finalizing gitstring"
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 21, 2013, 21:47 UTC
- Message-ID
- <xmqq7gfeu35g.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1377118173-23405-3-git-send-email-bcasey@nvidia.com>
Brandon Casey <bcasey@nvidia.com> writes:
Show 11 quoted lines
> From: Brandon Casey <drafnel@gmail.com> > > This reverts commit 69a8141a5d81925b7e08cb228535e9ea4a7a02e3. > > Old Bash (3.0) which is distributed with RHEL 4.X and other ancient > platforms that are still in wide use, does not have a printf that > supports -v. Let's revert this patch and go back to using printf > in the traditional way. > > Signed-off-by: Brandon Casey <drafnel@gmail.com> > ---
Is this something you can detect at load-time once, store the result in a private variable and then switch on it at runtime, something along the lines of...
# on load...
printf -v __git_printf_supports_v -- "%s" yes >/dev/null 2>&1
... if test "${__git_printf_supports_v}" = yes
then
printf -v gitstring -- "$printf_format" "$gitstring"
else
gitstring=$(printf -- "$printf_format" "$gitstring")
fiShow 20 quoted lines
> contrib/completion/git-prompt.sh | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index a81ef5a..7698ec4 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -433,11 +433,7 @@ __git_ps1 ()
> local gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
>
> if [ $pcmode = yes ]; then
> - if [[ -n ${ZSH_VERSION-} ]]; then
> - gitstring=$(printf -- "$printf_format" "$gitstring")
> - else
> - printf -v gitstring -- "$printf_format" "$gitstring"
> - fi
> + gitstring=$(printf -- "$printf_format" "$gitstring")
> PS1="$ps1pc_start$gitstring$ps1pc_end"
> else
> printf -- "$printf_format" "$gitstring"