summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder@ira.uka.de>2013-06-17 19:42:55 (GMT)
committerSZEDER Gábor <szeder@ira.uka.de>2013-06-24 16:03:37 (GMT)
commit69a8141a5d81925b7e08cb228535e9ea4a7a02e3 (patch)
treeb2ca3c8372beedbb4c7fa52fd461c042f8be2b98
parent14d7649748265fe9fe991439ca6ae0c9db7a27ab (diff)
downloadgit-69a8141a5d81925b7e08cb228535e9ea4a7a02e3.zip
git-69a8141a5d81925b7e08cb228535e9ea4a7a02e3.tar.gz
git-69a8141a5d81925b7e08cb228535e9ea4a7a02e3.tar.bz2
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>
-rw-r--r--contrib/completion/git-prompt.sh6
1 files changed, 5 insertions, 1 deletions
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