threads / patch / 33558

patchprompt: fix tracked files for zsh

Subject: [PATCH] prompt: fix tracked files for zsh

## tl;dr

10 messages between Apr 21, 2013 and Apr 21, 2013. Diffs are folded; open one to read it.

replies: 9people: 4as markdown or json

Felipe Contreras· Apr 21, 2013, 08:11 UTC · lore

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(-)
Show changes to contrib/completion/git-prompt.sh +5 −1
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· Apr 21, 2013, 08:21 UTC · re: Felipe Contreras · lore

Re: [PATCH] prompt: fix tracked files for zsh

Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 5 quoted lines
> +				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· Apr 21, 2013, 08:48 UTC · re: Andreas Schwab · lore

Re: [PATCH] prompt: fix tracked files for zsh

Andreas Schwab <schwab@linux-m68k.org> writes:
Show 9 quoted lines
> 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· Apr 21, 2013, 19:02 UTC · re: Junio C Hamano · lore

Re: [PATCH] prompt: fix tracked files for zsh

Junio C Hamano <gitster@pobox.com> writes:
Show 14 quoted lines
> 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· Apr 21, 2013, 21:00 UTC · re: Andreas Schwab · lore

Re: [PATCH] prompt: fix tracked files for zsh

On Sun, Apr 21, 2013 at 2:02 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
Show 18 quoted lines
> 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· Apr 21, 2013, 22:00 UTC · re: Felipe Contreras · lore

Re: [PATCH] prompt: fix tracked files for zsh

Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 21 quoted lines
> 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(-)
Show changes to contrib/completion/git-prompt.sh +1 −1
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· Apr 21, 2013, 22:32 UTC · re: Junio C Hamano · lore

Re: [PATCH] prompt: fix tracked files for zsh

On Sun, Apr 21, 2013 at 5:00 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
> 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.
Show 5 quoted lines
> 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
Junio C Hamano· Apr 21, 2013, 08:43 UTC · re: Felipe Contreras · lore

Re: [PATCH] prompt: fix tracked files for zsh

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?
Show 22 quoted lines
> 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· Apr 21, 2013, 08:43 UTC · re: Felipe Contreras · lore

Re: [PATCH] prompt: fix tracked files for zsh

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· Apr 21, 2013, 08:43 UTC · re: Felipe Contreras · lore

Re: [PATCH] prompt: fix tracked files for zsh

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?
Show 22 quoted lines
> 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

← back to recent threads