threads / rfc / 27370

RFC patchcompletion: __git_ps1() returns exit status now

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

## tl;dr

One message between May 16, 2011 and May 16, 2011. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Sergei Gavrikov· May 16, 2011, 13:23 UTC · lore
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(-)
Show changes to contrib/completion/git-completion.bash +6 −1
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

← back to recent threads