git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-prompt.sh: shorter equal upstream branch name
@ 2014-09-30 15:36 Julien Carsique
  2014-09-30 20:44 ` Richard Hansen
  2014-09-30 22:29 ` Junio C Hamano
  0 siblings, 2 replies; 9+ messages in thread
From: Julien Carsique @ 2014-09-30 15:36 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, SZEDER Gábor, Felipe Contreras,
	Ramkumar Ramachandra, Simon Oosthoek, Eduardo R. D'Avila,
	Richard Hansen, Julien Carsique

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-10-07 20:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-30 15:36 [PATCH] git-prompt.sh: shorter equal upstream branch name Julien Carsique
2014-09-30 20:44 ` Richard Hansen
2014-09-30 22:35   ` Junio C Hamano
2014-10-01  3:54     ` Richard Hansen
2014-10-01 17:49       ` Junio C Hamano
2014-10-07 15:57         ` Julien Carsique
2014-10-07 19:42           ` Richard Hansen
2014-10-07 20:10           ` Junio C Hamano
2014-09-30 22:29 ` Junio C Hamano

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 NNTP newsgroup(s).