bash prompt: avoid command substitution when finalizing gitstring

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>

SZEDER Gábor committed Jun 17, 2013 at 21:42 UTC 69a8141a5d81925b7e08cb228535e9ea4a7a02e3
1 file changed +5 -1
contrib/completion/git-prompt.sh
+5 -1
@@ -461,7 +461,11 @@ __git_ps1 ()
461 else
462 gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
463 fi
464 - gitstring=$(printf -- "$printf_format" "$gitstring")
464 + if [[ -n ${ZSH_VERSION-} ]]; then
465 + gitstring=$(printf -- "$printf_format" "$gitstring")
466 + else
467 + printf -v gitstring -- "$printf_format" "$gitstring"
468 + fi
469 PS1="$ps1pc_start$gitstring$ps1pc_end"
470 else
471 # NO color option unless in PROMPT_COMMAND mode