git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Justin Donnelly via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Justin Donnelly <justinrdonnelly@gmail.com>,
	Justin Donnelly <justinrdonnelly@gmail.com>
Subject: [PATCH 2/4] git-prompt: make upstream state indicator location consistent
Date: Fri, 25 Feb 2022 11:44:04 +0000	[thread overview]
Message-ID: <b503cac5ae3e89aa7b6f996567a5d7b4d2a05d29.1645789446.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1162.git.1645789446.gitgitgadget@gmail.com>

From: Justin Donnelly <justinrdonnelly@gmail.com>

Make upstream state indicator location more consistent with similar
state indicators (e.g. sparse). Group the short state indicator (`=`,
`<`, `>`, or `<>`) with other short state indicators immediately after
the branch name. Group the long state indicator (e.g. `u+2-1
origin/main`) with other long state indicators after the short state
indicators. Previously short and long upstream state indicators appeared
after all other state indicators.

Use a separator (`SP` or `GIT_PS1_STATESEPARATOR`) between branch name
and short upstream state indicator. Previously the short upstream state
indicator would sometimes appear directly adjacent to the branch name
(e.g. `(main=)`) instead of being separated (e.g. `(main =)`).

Signed-off-by: Justin Donnelly <justinrdonnelly@gmail.com>
---
 contrib/completion/git-prompt.sh | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 3997e099aa7..613389a53bc 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -109,7 +109,7 @@
 __git_printf_supports_v=
 printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
 
-# stores the divergence from upstream in $p
+# stores the divergence from upstream in $p (for short status) or $upstream (for verbose status)
 # used by GIT_PS1_SHOWUPSTREAM
 __git_ps1_show_upstream ()
 {
@@ -214,26 +214,26 @@ __git_ps1_show_upstream ()
 		*)	    # diverged from upstream
 			p="<>" ;;
 		esac
-	else
+	else # verbose, set upstream instead of p
 		case "$count" in
 		"") # no upstream
-			p="" ;;
+			upstream="" ;;
 		"0	0") # equal to upstream
-			p=" u=" ;;
+			upstream=" u=" ;;
 		"0	"*) # ahead of upstream
-			p=" u+${count#0	}" ;;
+			upstream=" u+${count#0	}" ;;
 		*"	0") # behind upstream
-			p=" u-${count%	0}" ;;
+			upstream=" u-${count%	0}" ;;
 		*)	    # diverged from upstream
-			p=" u+${count#*	}-${count%	*}" ;;
+			upstream=" u+${count#*	}-${count%	*}" ;;
 		esac
 		if [[ -n "$count" && -n "$name" ]]; then
 			__git_ps1_upstream_name=$(git rev-parse \
 				--abbrev-ref "$upstream_type" 2>/dev/null)
 			if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
-				p="$p \${__git_ps1_upstream_name}"
+				upstream="$upstream \${__git_ps1_upstream_name}"
 			else
-				p="$p ${__git_ps1_upstream_name}"
+				upstream="$upstream ${__git_ps1_upstream_name}"
 				# not needed anymore; keep user's
 				# environment clean
 				unset __git_ps1_upstream_name
@@ -512,7 +512,8 @@ __git_ps1 ()
 	local u=""
 	local h=""
 	local c=""
-	local p=""
+	local p="" # short version of upstream state indicator
+	local upstream="" # verbose version of upstream state indicator
 
 	if [ "true" = "$inside_gitdir" ]; then
 		if [ "true" = "$bare_repo" ]; then
@@ -568,8 +569,8 @@ __git_ps1 ()
 		b="\${__git_ps1_branch_name}"
 	fi
 
-	local f="$h$w$i$s$u"
-	local gitstring="$c$b${f:+$z$f}${sparse}$r$p"
+	local f="$h$w$i$s$u$p"
+	local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}"
 
 	if [ $pcmode = yes ]; then
 		if [ "${__git_printf_supports_v-}" != yes ]; then
-- 
gitgitgadget


  parent reply	other threads:[~2022-02-25 11:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25 11:44 [PATCH 0/4] In PS1 prompt, make upstream state indicators consistent with other state indicators Justin Donnelly via GitGitGadget
2022-02-25 11:44 ` [PATCH 1/4] git-prompt: rename `upstream` to `upstream_type` Justin Donnelly via GitGitGadget
2022-02-25 11:44 ` Justin Donnelly via GitGitGadget [this message]
2022-02-25 11:44 ` [PATCH 3/4] git-prompt: make long upstream state indicator consistent Justin Donnelly via GitGitGadget
2022-02-25 11:44 ` [PATCH 4/4] git-prompt: put upstream comments together Justin Donnelly via GitGitGadget
2022-02-25 12:22 ` [PATCH 0/4] In PS1 prompt, make upstream state indicators consistent with other state indicators Ævar Arnfjörð Bjarmason
2022-02-27  0:32   ` Justin Donnelly
2022-02-27 10:19     ` Ævar Arnfjörð Bjarmason
2022-02-27 19:57 ` [PATCH v2 " Justin Donnelly via GitGitGadget
2022-02-27 19:57   ` [PATCH v2 1/4] git-prompt: rename `upstream` to `upstream_type` Justin Donnelly via GitGitGadget
2022-02-27 19:57   ` [PATCH v2 2/4] git-prompt: make upstream state indicator location consistent Justin Donnelly via GitGitGadget
2022-02-27 19:57   ` [PATCH v2 3/4] git-prompt: make long upstream state indicator consistent Justin Donnelly via GitGitGadget
2022-02-27 19:57   ` [PATCH v2 4/4] git-prompt: put upstream comments together Justin Donnelly via GitGitGadget
2022-03-22 12:25   ` [PATCH v2 0/4] In PS1 prompt, make upstream state indicators consistent with other state indicators Ævar Arnfjörð Bjarmason
2022-03-23 20:06     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b503cac5ae3e89aa7b6f996567a5d7b4d2a05d29.1645789446.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=justinrdonnelly@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).