# [PATCH] prompt: fix tracked files for zsh

10 messages from 2013-04-21 to 2013-04-21. Participants: Felipe Contreras, Andreas Schwab, Junio C Hamano, Eric Sunshine.
Thread: https://gitlist.dev/t/33558

## Felipe Contreras, 2013-04-21 08:11

Subject: [PATCH] prompt: fix tracked files for zsh
Message-ID: <1366531890-19899-1-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1366531890-19899-1-git-send-email-felipe.contreras%40gmail.com

```
When this option is enabled, the prompt gets totally screwed in zsh
because all the codes start with % in zsh (like they are \ in bas). So
we need to escape the % character.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-prompt.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 756a951..4bedbcc 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -340,7 +340,11 @@ __git_ps1 ()
 			   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
 			   [ -n "$(git ls-files --others --exclude-standard)" ]
 			then
-				u="%"
+				if [ -n "${ZSH_VERSION-}" ]; then
+					u="%%"
+				else
+					u="%"
+				fi
 			fi
 
 			if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
-- 
1.8.2.1.790.g4588561

```

## Andreas Schwab, 2013-04-21 08:21

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <m2fvyk8fb8.fsf@igel.home>
URL: https://gitlist.dev/e/m2fvyk8fb8.fsf%40igel.home
In-Reply-To: <1366531890-19899-1-git-send-email-felipe.contreras@gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

> +				if [ -n "${ZSH_VERSION-}" ]; then
> +					u="%%"
> +				else
> +					u="%"
> +				fi

aka u="%${ZSH_VERSION:+%}"

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

```

## Junio C Hamano, 2013-04-21 08:43

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <7vr4i4uvdy.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr4i4uvdy.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1366531890-19899-1-git-send-email-felipe.contreras@gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

> When this option is enabled, the prompt gets totally screwed in zsh
> because all the codes start with % in zsh (like they are \ in bas). So
> we need to escape the % character.

It is not that I do not believe that $u needs to duplicate %% in
ZSH, but I hate it when I do not understand the explanation.  Could
you help me clarify what you meant by "codes" and "like they are \ in bas"?

Are you referring to things like \u (user) \h (host) as "code" and
"bas" was a simple typo of "bash"?  In other words, is my reading
below:

	... because '%' is used as an introducer of prompt
	customization in zsh (just like bash prompt uses '\' to
	introduce \u, \h, etc.), we need to give '%%' to get a
	literal per-cent character.

match what you meant to say?

> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  contrib/completion/git-prompt.sh | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index 756a951..4bedbcc 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -340,7 +340,11 @@ __git_ps1 ()
>  			   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
>  			   [ -n "$(git ls-files --others --exclude-standard)" ]
>  			then
> -				u="%"
> +				if [ -n "${ZSH_VERSION-}" ]; then
> +					u="%%"
> +				else
> +					u="%"
> +				fi
>  			fi
>  
>  			if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then

```

## Eric Sunshine, 2013-04-21 08:43

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <CAPig+cQqre7iW4DK+XSvFypng5sW=sK8os+ODz2kxYE8nkBw_Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcQqre7iW4DK%2BXSvFypng5sW%3DsK8os%2BODz2kxYE8nkBw_Q%40mail.gmail.com
In-Reply-To: <1366531890-19899-1-git-send-email-felipe.contreras@gmail.com>

```
On Sun, Apr 21, 2013 at 4:11 AM, Felipe Contreras
<felipe.contreras@gmail.com> wrote:
> When this option is enabled, the prompt gets totally screwed in zsh
> because all the codes start with % in zsh (like they are \ in bas). So

s/bas/bash/

> we need to escape the % character.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>

```

## Junio C Hamano, 2013-04-21 08:43

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <7vppxouvdp.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vppxouvdp.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1366531890-19899-1-git-send-email-felipe.contreras@gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

> When this option is enabled, the prompt gets totally screwed in zsh
> because all the codes start with % in zsh (like they are \ in bas). So
> we need to escape the % character.

It is not that I do not believe that $u needs to duplicate %% in
ZSH, but I hate it when I do not understand the explanation.  Could
you help me clarify what you meant by "codes" and "like they are \ in bas"?

Are you referring to things like \u (user) \h (host) as "code" and
"bas" was a simple typo of "bash"?  In other words, does my reading
below:

	... because '%' is used as an introducer of prompt
	customization in zsh (just like bash prompt uses '\' to
	introduce \u, \h, etc.), we need to give '%%' to get a
	literal per-cent character.

match what you meant to say?

> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  contrib/completion/git-prompt.sh | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index 756a951..4bedbcc 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -340,7 +340,11 @@ __git_ps1 ()
>  			   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
>  			   [ -n "$(git ls-files --others --exclude-standard)" ]
>  			then
> -				u="%"
> +				if [ -n "${ZSH_VERSION-}" ]; then
> +					u="%%"
> +				else
> +					u="%"
> +				fi
>  			fi
>  
>  			if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then

```

## Junio C Hamano, 2013-04-21 08:48

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <7vli8cuv5j.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vli8cuv5j.fsf%40alter.siamese.dyndns.org
In-Reply-To: <m2fvyk8fb8.fsf@igel.home>

```
Andreas Schwab <schwab@linux-m68k.org> writes:

> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> +				if [ -n "${ZSH_VERSION-}" ]; then
>> +					u="%%"
>> +				else
>> +					u="%"
>> +				fi
>
> aka u="%${ZSH_VERSION:+%}"

Do you need/want a colon there?  Even if it is empty, as long as it
is defined we would want this, no?

>
> Andreas.

```

## Andreas Schwab, 2013-04-21 19:02

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <m2a9or907f.fsf@igel.home>
URL: https://gitlist.dev/e/m2a9or907f.fsf%40igel.home
In-Reply-To: <7vli8cuv5j.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> Andreas Schwab <schwab@linux-m68k.org> writes:
>
>> Felipe Contreras <felipe.contreras@gmail.com> writes:
>>
>>> +				if [ -n "${ZSH_VERSION-}" ]; then
>>> +					u="%%"
>>> +				else
>>> +					u="%"
>>> +				fi
>>
>> aka u="%${ZSH_VERSION:+%}"
>
> Do you need/want a colon there?  Even if it is empty, as long as it
> is defined we would want this, no?

The original wouldn't.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

```

## Felipe Contreras, 2013-04-21 21:00

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <CAMP44s36TO6DQ_3j7rSOoOM6QS-Y0DW_z6WX_GF3ODFfupb6jg@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s36TO6DQ_3j7rSOoOM6QS-Y0DW_z6WX_GF3ODFfupb6jg%40mail.gmail.com
In-Reply-To: <m2a9or907f.fsf@igel.home>

```
On Sun, Apr 21, 2013 at 2:02 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>
>>> Felipe Contreras <felipe.contreras@gmail.com> writes:
>>>
>>>> +                           if [ -n "${ZSH_VERSION-}" ]; then
>>>> +                                   u="%%"
>>>> +                           else
>>>> +                                   u="%"
>>>> +                           fi
>>>
>>> aka u="%${ZSH_VERSION:+%}"
>>
>> Do you need/want a colon there?  Even if it is empty, as long as it
>> is defined we would want this, no?
>
> The original wouldn't.

I thought you were trying to improve the original ;)

-- 
Felipe Contreras

```

## Junio C Hamano, 2013-04-21 22:00

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <7vehe3sfwv.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vehe3sfwv.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAMP44s36TO6DQ_3j7rSOoOM6QS-Y0DW_z6WX_GF3ODFfupb6jg@mail.gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

> On Sun, Apr 21, 2013 at 2:02 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>>
>>>> Felipe Contreras <felipe.contreras@gmail.com> writes:
>>>>
>>>>> +                           if [ -n "${ZSH_VERSION-}" ]; then
>>>>> +                                   u="%%"
>>>>> +                           else
>>>>> +                                   u="%"
>>>>> +                           fi
>>>>
>>>> aka u="%${ZSH_VERSION:+%}"
>>>
>>> Do you need/want a colon there?  Even if it is empty, as long as it
>>> is defined we would want this, no?
>>
>> The original wouldn't.
>
> I thought you were trying to improve the original ;)

OK, so I _think_ everybody is in agreement that the patch should
look like this.  OK?

-- >8 --
From: Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH] prompt: fix untracked files for zsh

With "bash.showUntrackedFiles" option, presense of untracked files
is signalled by adding a per-cent sign '%' to the prompt.  But
because '%' is used as an escape character to introduce prompt
customization in zsh (just like bash prompt uses '\' to escape \u,
\h, etc.), we need to say '%%' to get a literal per-cent.

Helped-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-prompt.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 756a951..054c52e 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -340,7 +340,7 @@ __git_ps1 ()
 			   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
 			   [ -n "$(git ls-files --others --exclude-standard)" ]
 			then
-				u="%"
+				u="%${ZSH_VERSION+%}"
 			fi
 
 			if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then

```

## Felipe Contreras, 2013-04-21 22:32

Subject: Re: [PATCH] prompt: fix tracked files for zsh
Message-ID: <CAMP44s0xMX2-sDzouYtCRzqRQLHOCdUDR_+G-50Mv9wG2P+EFQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s0xMX2-sDzouYtCRzqRQLHOCdUDR_%2BG-50Mv9wG2P%2BEFQ%40mail.gmail.com
In-Reply-To: <7vehe3sfwv.fsf@alter.siamese.dyndns.org>

```
On Sun, Apr 21, 2013 at 5:00 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> On Sun, Apr 21, 2013 at 2:02 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
>>> Junio C Hamano <gitster@pobox.com> writes:
>>>
>>>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>>>
>>>>> Felipe Contreras <felipe.contreras@gmail.com> writes:
>>>>>
>>>>>> +                           if [ -n "${ZSH_VERSION-}" ]; then
>>>>>> +                                   u="%%"
>>>>>> +                           else
>>>>>> +                                   u="%"
>>>>>> +                           fi
>>>>>
>>>>> aka u="%${ZSH_VERSION:+%}"
>>>>
>>>> Do you need/want a colon there?  Even if it is empty, as long as it
>>>> is defined we would want this, no?
>>>
>>> The original wouldn't.
>>
>> I thought you were trying to improve the original ;)
>
> OK, so I _think_ everybody is in agreement that the patch should
> look like this.  OK?
>
> -- >8 --
> From: Felipe Contreras <felipe.contreras@gmail.com>
> Subject: [PATCH] prompt: fix untracked files for zsh
>
> With "bash.showUntrackedFiles" option,

Not exactly correct, it can also be GIT_PS1_SHOWUNTRACKEDFILES.

> presense of untracked files
> is signalled by adding a per-cent sign '%' to the prompt.  But
> because '%' is used as an escape character to introduce prompt
> customization in zsh (just like bash prompt uses '\' to escape \u,
> \h, etc.), we need to say '%%' to get a literal per-cent.

Otherwise it's fine.

Cheers.

-- 
Felipe Contreras

```
