Re: [PATCH] completion: Allow dash as the first character for __git_ps1

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] completion: Allow dash as the first character for __git_ps1

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:53:07

Christian Hammerl [off-list ref] writes:
quoted hunk
If the argument for `__git_ps1` begins with a dash, `printf` tries to
interpret it as an option which results in an error message.
The problem is solved by adding '--' before the argument to tell
`printf` to not interpret the following argument as an option.
Adding '--' directly to the argument does not help because the argument
is enclosed by double quotes.

Signed-off-by: Christian Hammerl <redacted>
---
 contrib/completion/git-completion.bash |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 91c7acb..61ff152 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -313,7 +313,7 @@ __git_ps1 ()
 		fi
 
 		local f="$w$i$s$u"
-		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
+		printf -- "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
 	fi
 }
Hmm, so you may be doing something like PS1='\W$(__git_ps1 "-%s")'?
OK, and thanks.  

Re: [PATCH] completion: Allow dash as the first character for __git_ps1

From: Christian Hammerl <hidden>
Date: 2016-06-15 22:53:07

Yes, kind of.

It is more like PS1='\W$(__git_ps1 "-[ %s ]")'. And i am fixing it after each update on my machine. ;-)



Junio C Hamano [off-list ref] schrieb:
Christian Hammerl [off-list ref] writes:
quoted
If the argument for `__git_ps1` begins with a dash, `printf` tries to
interpret it as an option which results in an error message.
The problem is solved by adding '--' before the argument to tell
`printf` to not interpret the following argument as an option.
Adding '--' directly to the argument does not help because the
argument
quoted
is enclosed by double quotes.

Signed-off-by: Christian Hammerl <redacted>
---
 contrib/completion/git-completion.bash |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash
b/contrib/completion/git-completion.bash
quoted
index 91c7acb..61ff152 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -313,7 +313,7 @@ __git_ps1 ()
 		fi
 
 		local f="$w$i$s$u"
-		printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
+		printf -- "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
 	fi
 }
Hmm, so you may be doing something like PS1='\W$(__git_ps1 "-%s")'?
OK, and thanks.  
-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help