]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bash prompt: avoid command substitution when finalizing gitstring
authorSZEDER Gábor <szeder@ira.uka.de>
Mon, 17 Jun 2013 19:42:55 +0000 (21:42 +0200)
committerSZEDER Gábor <szeder@ira.uka.de>
Mon, 24 Jun 2013 16:03:37 +0000 (18:03 +0200)
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 <szeder@ira.uka.de>
contrib/completion/git-prompt.sh

index 5ea6a68bc0f6bc707669840f68fee680544f7c2a..7152ae49fb760d28af4290117844962a19eb7621 100644 (file)
@@ -461,7 +461,11 @@ __git_ps1 ()
                else
                        gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
                fi
-               gitstring=$(printf -- "$printf_format" "$gitstring")
+               if [[ -n ${ZSH_VERSION-} ]]; then
+                       gitstring=$(printf -- "$printf_format" "$gitstring")
+               else
+                       printf -v gitstring -- "$printf_format" "$gitstring"
+               fi
                PS1="$ps1pc_start$gitstring$ps1pc_end"
        else
                # NO color option unless in PROMPT_COMMAND mode