Skip to content

Commit 69a8141

Browse files
committed
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 <[email protected]>
1 parent 14d7649 commit 69a8141

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

contrib/completion/git-prompt.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,11 @@ __git_ps1 ()
461461
else
462462
gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
463463
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
465469
PS1="$ps1pc_start$gitstring$ps1pc_end"
466470
else
467471
# NO color option unless in PROMPT_COMMAND mode

0 commit comments

Comments
 (0)