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

[RFC/PATCH] completion: __git_ps1() returns exit status now

From
SGSergei Gavrikov <sergei.gavrikov@gmail.com>
Date
May 16, 2011, 13:23 UTC
Message-ID
<alpine.DEB.2.00.1105161615430.3397@sg-pc.belvok.com>
SYNOPSIS
        $(__git_ps1 || __other_vcs_ps1)

It would be great if __git_ps1() could return exit status on it's finish, otherwise they have to check git_ps1 text output or recall __gitdir() to suppress alternative VCS prompt(s).

Patch attached, although I would prefer to check it at once, e.g.,
        if [ -z "$g" ]; then return 1; fi
        ...
        return 0
however, I was in doubt about more verbose delta in such a case.
If I request the bad things or miss something, please, forget it.
Signed-off-by: Sergei Gavrikov <sergei.gavrikov@gmail.com>
---
 contrib/completion/git-completion.bash |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b81f444..8b660ca 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -222,7 +222,8 @@ __git_ps1_show_upstream ()
 
 
 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
-# returns text to add to bash PS1 prompt (includes branch name)
+# prints text to add to bash PS1 prompt (includes branch name),
+# returns 0 (exit status) if gitdir was processed, otherwise 1.
 __git_ps1 ()
 {
 	local g="$(__gitdir)"
@@ -313,7 +314,11 @@ __git_ps1 ()
 
 		local f="$w$i$s$u"
 		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
+
+		return 0
 	fi
+
+	return 1
 }
 
 # __gitcomp_1 requires 2 arguments
-- 
1.7.0.4
Message 1 of 1 in “completion: __git_ps1() returns exit status now”
  1. completion: __git_ps1() returns exit status nowSergei Gavrikov, May 16, 2011

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.