[PATCH] bash completion: add space between branch name and status flags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Improve the readability of the bash prompt by adding a space between
the branch name and the status flags (dirty, stash, untracked).

While we are cleaning up this section of code, the two cases for
formatting the prompt are identical except for the format string,
so make them the same.

Suggested-by: Roman Fietze <roman.fietze@xxxxxxxxxxxxx>
Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
   Junio C Hamano <gitster@xxxxxxxxx> wrote:
   > I notice that printf argument look very similar.  Maybe we want to do
   > something like
   > 
   >     printf "${1:-" (%s)"}" ...
   > 
   > to avoid duplication?
   
   Ack.

   Because its rather far from the original poster's patch, I've
   taken blame for it.
   
 contrib/completion/git-completion.bash |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index fbfa5f2..9ed7df2 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -163,11 +163,9 @@ __git_ps1 ()
 			fi
 		fi
 
-		if [ -n "${1-}" ]; then
-			printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
-		else
-			printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
-		fi
+		local f="$w$i$s$u"
+		f="${f:+ $f}$r"
+		printf "${1:- (%s)}" "$c${b##refs/heads/}$f"
 	fi
 }
 
-- 
1.6.6.325.g6f5f

-- 
Shawn.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]