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>
This commit is contained in:
parent
14d7649748
commit
69a8141a5d
@ -461,7 +461,11 @@ __git_ps1 ()
|
|||||||
else
|
else
|
||||||
gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
|
gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
|
||||||
fi
|
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"
|
PS1="$ps1pc_start$gitstring$ps1pc_end"
|
||||||
else
|
else
|
||||||
# NO color option unless in PROMPT_COMMAND mode
|
# NO color option unless in PROMPT_COMMAND mode
|
||||||
|
Loading…
Reference in New Issue
Block a user