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

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Dec 31, 2009, 03:04 UTC
Message-ID
<20091231030438.GH6914@spearce.org>
In-Reply-To
<7veimc1cv6.fsf@alter.siamese.dyndns.org>

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@telemotive.de>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
   Junio C Hamano <gitster@pobox.com> 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.
Previous: Junio C HamanoNext: Roman Fietze
Message 6 of 7 in “bash completion: add space between branch name and status flags”
  1. bash completion: add space between branch name and status flagsRoman Fietze, Nov 20, 2009
  2. Junio C HamanoNov 20, 2009
  3. Nanako ShiraishiDec 30, 2009
  4. Shawn O. PearceDec 30, 2009
  5. Junio C HamanoDec 30, 2009
  6. bash completion: add space between branch name and status flagsShawn O. Pearce, Dec 31, 2009
  7. Roman FietzeJan 6, 2010

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.