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

3 messages from 2012-02-20 to 2012-02-21. Participants: Christian Hammerl, Junio C Hamano.
Thread: https://gitlist.dev/t/29672

## Christian Hammerl, 2012-02-20 12:17

Subject: [PATCH] completion: Allow dash as the first character for __git_ps1
Message-ID: <1329740273-5580-1-git-send-email-info@christian-hammerl.de>
URL: https://gitlist.dev/e/1329740273-5580-1-git-send-email-info%40christian-hammerl.de

```
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 <info@christian-hammerl.de>
---
 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
 }
 
-- 
1.7.9

```

## Junio C Hamano, 2012-02-21 20:40

Subject: Re: [PATCH] completion: Allow dash as the first character for __git_ps1
Message-ID: <7vty2jgbsh.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vty2jgbsh.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1329740273-5580-1-git-send-email-info@christian-hammerl.de>

```
Christian Hammerl <info@christian-hammerl.de> writes:

> 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 <info@christian-hammerl.de>
> ---
>  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.  

```

## Christian Hammerl, 2012-02-21 20:49

Subject: Re: [PATCH] completion: Allow dash as the first character for __git_ps1
Message-ID: <80e5224c-66f4-4bdf-9e0e-9aeb7f4f319d@email.android.com>
URL: https://gitlist.dev/e/80e5224c-66f4-4bdf-9e0e-9aeb7f4f319d%40email.android.com
In-Reply-To: <7vty2jgbsh.fsf@alter.siamese.dyndns.org>

```
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 <gitster@pobox.com> schrieb:

>Christian Hammerl <info@christian-hammerl.de> writes:
>
>> 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 <info@christian-hammerl.de>
>> ---
>>  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.  

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

```
