Updated git-prompt.sh to quote variables
An error was thrown (`bash: [: =: unary operator expected`) when using the __git_ps1_colorize_gitstring function outside of the one place it's called (line 512), because the "detached" variable was not quoted, and was unset.
Diff
1diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh
2index fd2b049dbde3cd6b1a2583e7c32f3ea2915052be..3e86e9ccab3e14d5a27c796ea5977e88151da127 100644
3--- a/plugins/gitfast/git-prompt.sh
4+++ b/plugins/gitfast/git-prompt.sh
5@@ -219,7 +219,7 @@ __git_ps1_show_upstream ()
6 if [[ -n "$count" && -n "$name" ]]; then
7 __git_ps1_upstream_name=$(git rev-parse \
8 --abbrev-ref "$upstream" 2>/dev/null)
9- if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
10+ if [ "$pcmode" = "yes" ] && [ "$ps1_expanded" = "yes" ]; then
11 p="$p \${__git_ps1_upstream_name}"
12 else
13 p="$p ${__git_ps1_upstream_name}"
14@@ -237,7 +237,7 @@ __git_ps1_show_upstream ()
15 # to build a gitstring.
16 __git_ps1_colorize_gitstring ()
17 {
18- if [[ -n ${ZSH_VERSION-} ]]; then
19+ if [[ -n "${ZSH_VERSION-}" ]]; then
20 local c_red='%F{red}'
21 local c_green='%F{green}'
22 local c_lblue='%F{blue}'
23@@ -255,7 +255,7 @@ __git_ps1_colorize_gitstring ()
24 local flags_color="$c_lblue"
2526 local branch_color=""
27- if [ $detached = no ]; then
28+ if [ "$detached" = no ]; then
29 branch_color="$ok_color"
30 else
31 branch_color="$bad_color"
32@@ -508,13 +508,13 @@ __git_ps1 ()
3334 # NO color option unless in PROMPT_COMMAND mode or it's Zsh
35 if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
36- if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
37+ if [ "$pcmode" = "yes" ] || [ -n "${ZSH_VERSION-}" ]; then
38 __git_ps1_colorize_gitstring
39 fi
40 fi
4142 b=${b##refs/heads/}
43- if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
44+ if [ "$pcmode" = "yes" ] && [ "$ps1_expanded" = "yes" ]; then
45 __git_ps1_branch_name=$b
46 b="\${__git_ps1_branch_name}"
47 fi
48@@ -522,8 +522,8 @@ __git_ps1 ()
49 local f="$w$i$s$u"
50 local gitstring="$c$b${f:+$z$f}$r$p"
5152- if [ $pcmode = yes ]; then
53- if [ "${__git_printf_supports_v-}" != yes ]; then
54+ if [ "$pcmode" = "yes" ]; then
55+ if [ "${__git_printf_supports_v-}" != "yes" ]; then
56 gitstring=$(printf -- "$printf_format" "$gitstring")
57 else
58 printf -v gitstring -- "$printf_format" "$gitstring"