From 69a8141a5d81925b7e08cb228535e9ea4a7a02e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SZEDER=20G=C3=A1bor?= Date: Mon, 17 Jun 2013 21:42:55 +0200 Subject: bash prompt: avoid command substitution when finalizing gitstring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ' to directly assign the output to that variable. zsh's printf doesn't support the '-v ' option, so stick with the command substitution when under zsh. Signed-off-by: SZEDER Gábor diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 5ea6a68..7152ae4 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -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 -- cgit v0.10.2-6-g49f6