Before setting $PS1, __git_ps1() uses a command substitution to
redirect the output from a printf into a variable.  Spare the overhead
of fork()ing a subshell by using 'printf -v <var>' to directly assign
the output to that variable.

zsh's printf doesn't support the '-v <var>' option, so stick with the
command substitution when under zsh.

Signed-off-by: SZEDER Gábor <>
 contrib/completion/ | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/contrib/completion/ b/contrib/completion/
index 5ea6a68b..7152ae49 100644
--- a/contrib/completion/
+++ b/contrib/completion/
@@ -461,7 +461,11 @@ __git_ps1 ()
-               gitstring=$(printf -- "$printf_format" "$gitstring")
+               if [[ -n ${ZSH_VERSION-} ]]; then
+                       gitstring=$(printf -- "$printf_format" "$gitstring")
+               else
+                       printf -v gitstring -- "$printf_format" "$gitstring"
+               fi
                # NO color option unless in PROMPT_COMMAND mode

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to