From: Brandon Casey <bcasey@nvidia.com>
To: <gitster@pobox.com>
Cc: <git@vger.kernel.org>, <szeder@ira.uka.de>,
Brandon Casey <drafnel@gmail.com>
Subject: [PATCH] contrib/git-prompt.sh: handle missing 'printf -v' more gracefully
Date: Wed, 21 Aug 2013 18:17:22 -0700 [thread overview]
Message-ID: <1377134242-15012-1-git-send-email-bcasey@nvidia.com> (raw)
In-Reply-To: <CA+sFfMfa422PF1inOOeTBRE7HRqL5zwCJNagx9Ya0i_LbpwQcg@mail.gmail.com>
From: Brandon Casey <drafnel@gmail.com>
Old Bash (3.0) which is distributed with RHEL 4.X and other ancient
platforms that are still in wide use, do not have a printf that
supports -v. Neither does Zsh (which is already handled in the code).
As suggested by Junio, let's test whether printf supports the -v
option and store the result. Then later, we can use it to
determine whether 'printf -v' can be used, or whether printf
must be called in a subshell.
Signed-off-by: Brandon Casey <drafnel@gmail.com>
---
This replaces [PATCH 3/3] Revert "bash prompt: avoid command substitution
when finalizing gitstring".
This may or may not need to be updated to use "${var-}" depending on
your response to my other email, but this seems sufficient.
-Brandon
contrib/completion/git-prompt.sh | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index a81ef5a..639888a 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -84,6 +84,10 @@
# the colored output of "git status -sb" and are available only when
# using __git_ps1 for PROMPT_COMMAND or precmd.
+# check whether printf supports -v
+__git_printf_supports_v=
+printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
+
# stores the divergence from upstream in $p
# used by GIT_PS1_SHOWUPSTREAM
__git_ps1_show_upstream ()
@@ -433,10 +437,10 @@ __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
+ if test "$__git_printf_supports_v" = yes; then
printf -v gitstring -- "$printf_format" "$gitstring"
+ else
+ gitstring=$(printf -- "$printf_format" "$gitstring")
fi
PS1="$ps1pc_start$gitstring$ps1pc_end"
else
--
1.8.4.rc0.2.g6cf5c31
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
next prev parent reply other threads:[~2013-08-22 1:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-21 20:49 [PATCH 1/3] git-completion.bash: use correct Bash/Zsh array length syntax Brandon Casey
2013-08-21 20:49 ` [PATCH 2/3] t9902-completion.sh: old Bash still does not support array+=('') notation Brandon Casey
2013-08-21 20:49 ` [PATCH 3/3] Revert "bash prompt: avoid command substitution when finalizing gitstring" Brandon Casey
2013-08-21 21:47 ` Junio C Hamano
2013-08-21 22:08 ` Brandon Casey
2013-08-22 0:22 ` Junio C Hamano
2013-08-22 0:33 ` Brandon Casey
2013-08-22 1:17 ` Brandon Casey [this message]
2013-08-22 1:39 ` [PATCH] contrib/git-prompt.sh: handle missing 'printf -v' more gracefully Brandon Casey
2013-08-22 1:27 ` [PATCH 3/3] Revert "bash prompt: avoid command substitution when finalizing gitstring" Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1377134242-15012-1-git-send-email-bcasey@nvidia.com \
--to=bcasey@nvidia.com \
--cc=drafnel@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=szeder@ira.uka.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).