git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-prompt.sh: shorter equal upstream branch name

From
Julien Carsique <julien.carsique@gmail.com>
Date
Sep 30, 2014, 15:36 UTC
Message-ID
<1412091370-11727-1-git-send-email-jcarsique@nuxeo.com>
From: Julien Carsique <julien.carsique@gmail.com>

When using the "name" option of GIT_PS1_SHOWUPSTREAM to show the upstream abbrev name, if the upstream name is the same as the local name, then some space could be saved in the prompt. This is especially needed on long branch names.

Replace the upstream name with the sign '=' if equal to the local one.
Example:    [master * u= origin/=]$
instead of: [master * u= origin/master]$
Signed-off-by: Julien Carsique <julien.carsique@gmail.com>
---
 contrib/completion/git-prompt.sh | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index c5473dc..a9aba20 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -209,6 +209,13 @@ __git_ps1_show_upstream ()
 		if [[ -n "$count" && -n "$name" ]]; then
 			__git_ps1_upstream_name=$(git rev-parse \
 				--abbrev-ref "$upstream" 2>/dev/null)
+
+			__head=${b##refs/heads/}
+			if [ "$__head" = "${__git_ps1_upstream_name##*/}" ]; then
+				__git_ps1_upstream_name=${__git_ps1_upstream_name/$__head/=}
+			fi
+			unset __head
+
 			if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
 				p="$p \${__git_ps1_upstream_name}"
 			else
-- 
2.1.0
Next: Richard Hansen
Message 1 of 9 in “git-prompt.sh: shorter equal upstream branch name”
  1. git-prompt.sh: shorter equal upstream branch nameJulien Carsique, Sep 30, 2014
  2. Richard HansenSep 30, 2014
  3. Junio C HamanoSep 30, 2014
  4. Richard HansenOct 1, 2014
  5. Junio C HamanoOct 1, 2014
  6. Julien CarsiqueOct 7, 2014
  7. Richard HansenOct 7, 2014
  8. Junio C HamanoOct 7, 2014
  9. Junio C HamanoSep 30, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.