threads / patch / 26773

patchcompletion: Add space to PS1 when showing upstream

Subject: [PATCH] completion: Add space to PS1 when showing upstream

## tl;dr

2 messages between Mar 18, 2011 and Mar 18, 2011. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Todd Zullinger· Mar 18, 2011, 15:02 UTC · lore

Depending on whether other changes were present or displayed in PS1, the prompt may have lacked a space between the branch and the upstream marker. Add this space as needed so the branch name and upstream state aren't confusingly mixed.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
 contrib/completion/git-completion.bash |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Show changes to contrib/completion/git-completion.bash +1 −0
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 0b0b913..e5af5f6 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -312,6 +312,7 @@ __git_ps1 ()
 		fi
 
 		local f="$w$i$s$u"
+		[[ -z $f ]] && p="${p:+ $p}"
 		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
 	fi
 }
-- 
1.7.4.1

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Giving money and power to government is like giving whiskey and car
keys to teenage boys.
    -- P.J. O'Rourke
Junio C Hamano· Mar 18, 2011, 20:01 UTC · re: Todd Zullinger · lore

Re: [PATCH] completion: Add space to PS1 when showing upstream

Todd Zullinger <tmz@pobox.com> writes:
> Depending on whether other changes were present or displayed in PS1, the
> prompt may have lacked a space between the branch and the upstream
> marker.

The grossly misnamed __git_ps1_show_upstream that does not show anything but only sets variable $p gives a non-alphanumeric mnemonic (e.g. p=">") that is not ambiguous without an extra leading SP under non verbose mode to make things shorter, and in verbose mode the returned string comes its own leading SP, e.g. " u+" followed by number of commits. So why would you want an extra SP in front of that SP that already exists?

Show 8 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 0b0b913..e5af5f6 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -312,6 +312,7 @@ __git_ps1 ()
>  		local f="$w$i$s$u"
> +		[[ -z $f ]] && p="${p:+ $p}"
>  		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"

Besides, you confused me with the description. You are checking $f to decide if you add an extra SP in front of $p but what comes in the end result is "$f$r$p", so "between the branch and marker" is not even true. Also why is $r ignored while deciding if you need this extra SP in the first place?

I also happen to think that the user should not even be worried about the divergence with the upstream when the repository is in any of the special states, in which case $r is not empty (e.g. "|REBASE-i"). So the above part may become:

	local f="$w$i$s$u"
	printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}${p:-$r}"
But that would be a separate topic.

← back to recent threads