git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-completion: workaround zsh COMPREPLY bug
@ 2012-01-25  1:37 Felipe Contreras
  2012-01-25  7:41 ` Matthieu Moy
  2012-01-26 22:00 ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Felipe Contreras @ 2012-01-25  1:37 UTC (permalink / raw)
  To: git; +Cc: gitster, Matthieu Moy, Felipe Contreras

zsh adds a backslash (foo\ ) for each item in the COMPREPLY array if IFS
doesn't contain spaces. This issue has been reported[1], but there is no
solution yet.

This wasn't a problem due to another bug[2], which was fixed in zsh
version 4.3.12. After this change, 'git checkout ma<tab>' would resolve
to 'git checkout master\ '.

Aditionally, the introduction of __gitcomp_nl in commit a31e626
(completion: optimize refs completion) in git also made the problem
apparent, as Matthieu Moy reported.

The simplest and most generic solution is to hide all the changes we do
to IFS, so that "foo \nbar " is recognized by zsh as "foo bar". This
works on versions of git before and after the introduction of
__gitcomp_nl (a31e626), and versions of zsh before and after 4.3.12.

Once zsh is fixed, we should conditionally disable this workaround to
have the same benefits as bash users.

[1] http://www.zsh.org/mla/workers/2012/msg00053.html
[2] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b0062ba..c83c734 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2631,6 +2631,10 @@ _git ()
 		# workaround zsh's bug that leaves 'words' as a special
 		# variable in versions < 4.3.12
 		typeset -h words
+
+		# another workaround for zsh because it would quote spaces in
+		# the COMPREPLY array if IFS doesn't contain spaces
+		typeset -h IFS
 	fi
 
 	local cur words cword prev
@@ -2687,6 +2691,10 @@ _gitk ()
 		# workaround zsh's bug that leaves 'words' as a special
 		# variable in versions < 4.3.12
 		typeset -h words
+
+		# another workaround for zsh because it would quote spaces in
+		# the COMPREPLY array if IFS doesn't contain spaces
+		typeset -h IFS
 	fi
 
 	local cur words cword prev
-- 
1.7.8.rc1.14.g248db

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] git-completion: workaround zsh COMPREPLY bug
  2012-01-25  1:37 [PATCH] git-completion: workaround zsh COMPREPLY bug Felipe Contreras
@ 2012-01-25  7:41 ` Matthieu Moy
  2012-01-25 12:16   ` Felipe Contreras
  2012-01-26 22:00 ` Junio C Hamano
  1 sibling, 1 reply; 7+ messages in thread
From: Matthieu Moy @ 2012-01-25  7:41 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: git, gitster

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

> The simplest and most generic solution is to hide all the changes we do
> to IFS, so that "foo \nbar " is recognized by zsh as "foo bar". This
> works on versions of git before and after the introduction of
> __gitcomp_nl (a31e626), and versions of zsh before and after 4.3.12.
[...]
> +
> +		# another workaround for zsh because it would quote spaces in
> +		# the COMPREPLY array if IFS doesn't contain spaces
> +		typeset -h IFS

No time to test right now, but is this not going to

1) leave IFS as hidden even outside the completion script, possibly
affecting unrelated scripts that would need to set IFS as local and keep
its special effect?

2) break cases where strings are to be split on \n only (e.g. see
"foo bar\nboz" as three possible completions "foo", "bar", "boz" instead
of "foo bar" and "boz"?

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git-completion: workaround zsh COMPREPLY bug
  2012-01-25  7:41 ` Matthieu Moy
@ 2012-01-25 12:16   ` Felipe Contreras
  2012-01-25 22:02     ` Matthieu Moy
  0 siblings, 1 reply; 7+ messages in thread
From: Felipe Contreras @ 2012-01-25 12:16 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, gitster

On Wed, Jan 25, 2012 at 9:41 AM, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> wrote:
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> The simplest and most generic solution is to hide all the changes we do
>> to IFS, so that "foo \nbar " is recognized by zsh as "foo bar". This
>> works on versions of git before and after the introduction of
>> __gitcomp_nl (a31e626), and versions of zsh before and after 4.3.12.
> [...]
>> +
>> +             # another workaround for zsh because it would quote spaces in
>> +             # the COMPREPLY array if IFS doesn't contain spaces
>> +             typeset -h IFS
>
> No time to test right now, but is this not going to
>
> 1) leave IFS as hidden even outside the completion script, possibly
> affecting unrelated scripts that would need to set IFS as local and keep
> its special effect?

What special effect?

Unrelated scripts can still set IFS as local.

You can test this:

---
#!/bin/sh

if [[ -n ${ZSH_VERSION-} ]]; then
    autoload -U +X bashcompinit && bashcompinit
fi

_foo()
{
    typeset -h IFS
    local cur="${COMP_WORDS[COMP_CWORD]}"
    local IFS=$'\n'
    w[0]='first '
    w[1]='second and space '
    w[2]='third\\ quoted\\ space '
    ./test1 >> /tmp/t1.txt
    COMPREPLY=( $(compgen -W "${w[*]}" -- $cur) )
}
complete -o nospace -F _foo foo
---

test1:
---
#!/bin/sh

test1() {
	local IFS=$'\n'
	w=( $(echo -e "foo \nbar"))
	echo "test1: 0:'${w[0]}' 1:'${w[1]}'"
}

test1

w=( $(echo -e "foo \nbar"))
echo "test2: 0:'${w[0]}' 1:'${w[1]}'"
---

The result in /tmp/t1.txt would be:
test1: 0:'foo ' 1:'bar'
test2: 0:'foo' 1:'bar'

Regardless of whether you use typeset -h or not.

> 2) break cases where strings are to be split on \n only (e.g. see
> "foo bar\nboz" as three possible completions "foo", "bar", "boz" instead
> of "foo bar" and "boz"?

Those cases are already broken, which is what I reported to the zsh
mailing list. You would get "foo\ bar" and "boz", and that's after
4.3.12; before, compgen -W would still break the completions in 3,
because they did 'results+=( $words )', instead of 'results+=(
"$words" )'.

Cheers.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git-completion: workaround zsh COMPREPLY bug
  2012-01-25 12:16   ` Felipe Contreras
@ 2012-01-25 22:02     ` Matthieu Moy
  2012-01-28 17:18       ` Felipe Contreras
  0 siblings, 1 reply; 7+ messages in thread
From: Matthieu Moy @ 2012-01-25 22:02 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: git, gitster

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

>>> +             typeset -h IFS
>>
>> No time to test right now, but is this not going to
>>
>> 1) leave IFS as hidden even outside the completion script, possibly
>> affecting unrelated scripts that would need to set IFS as local and keep
>> its special effect?
>
> What special effect?
>
> Unrelated scripts can still set IFS as local.

OK, I missed the fact that typeset -h had only local effect.

>> 2) break cases where strings are to be split on \n only (e.g. see
>> "foo bar\nboz" as three possible completions "foo", "bar", "boz" instead
>> of "foo bar" and "boz"?
>
> Those cases are already broken, which is what I reported to the zsh
> mailing list. You would get "foo\ bar" and "boz", and that's after
> 4.3.12; before, compgen -W would still break the completions in 3,
> because they did 'results+=( $words )', instead of 'results+=(
> "$words" )'.

Makes sense.

I still have a minor comment: maybe part of your commit message could go
to a comment in the code as well, in particular the "Once zsh is fixed"
part, to help future contributors to actually disable the workaround
when possible in the future.

Tested-by: Matthieu Moy <Matthieu.Moy@imag.fr>

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git-completion: workaround zsh COMPREPLY bug
  2012-01-25  1:37 [PATCH] git-completion: workaround zsh COMPREPLY bug Felipe Contreras
  2012-01-25  7:41 ` Matthieu Moy
@ 2012-01-26 22:00 ` Junio C Hamano
  2012-01-27 16:33   ` Felipe Contreras
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2012-01-26 22:00 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: git, Matthieu Moy

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

> zsh adds a backslash (foo\ ) for each item in the COMPREPLY array if IFS
> doesn't contain spaces. This issue has been reported[1], but there is no
> solution yet.
> ...
> Once zsh is fixed, we should conditionally disable this workaround to
> have the same benefits as bash users.
>
> [1] http://www.zsh.org/mla/workers/2012/msg00053.html
> [2] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d

That 2e25dfb8 only says:

    Rocky Bernstein: 29135 (plus tweaks): compgen -W in bash completion

without any explanation, which is not very useful.

Do you have a bug tracker ID or something for [1] above, with which I can
amend the patch as Matthieu suggests?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git-completion: workaround zsh COMPREPLY bug
  2012-01-26 22:00 ` Junio C Hamano
@ 2012-01-27 16:33   ` Felipe Contreras
  0 siblings, 0 replies; 7+ messages in thread
From: Felipe Contreras @ 2012-01-27 16:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Matthieu Moy

On Fri, Jan 27, 2012 at 12:00 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> zsh adds a backslash (foo\ ) for each item in the COMPREPLY array if IFS
>> doesn't contain spaces. This issue has been reported[1], but there is no
>> solution yet.
>> ...
>> Once zsh is fixed, we should conditionally disable this workaround to
>> have the same benefits as bash users.
>>
>> [1] http://www.zsh.org/mla/workers/2012/msg00053.html
>> [2] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d
>
> That 2e25dfb8 only says:
>
>    Rocky Bernstein: 29135 (plus tweaks): compgen -W in bash completion
>
> without any explanation, which is not very useful.

Yeah, they development practices leaves a lot to be desired.

> Do you have a bug tracker ID or something for [1] above, with which I can
> amend the patch as Matthieu suggests?

I don't think there's something like that, but here's the original discussion:

http://thread.gmane.org/gmane.comp.shells.zsh.devel/22541

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] git-completion: workaround zsh COMPREPLY bug
  2012-01-25 22:02     ` Matthieu Moy
@ 2012-01-28 17:18       ` Felipe Contreras
  0 siblings, 0 replies; 7+ messages in thread
From: Felipe Contreras @ 2012-01-28 17:18 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, gitster

On Thu, Jan 26, 2012 at 12:02 AM, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> wrote:
> I still have a minor comment: maybe part of your commit message could go
> to a comment in the code as well, in particular the "Once zsh is fixed"
> part, to help future contributors to actually disable the workaround
> when possible in the future.

FTR, I've fixed all the issues in zsh's bash completion:

http://thread.gmane.org/gmane.comp.shells.zsh.devel/24290

Now I don't need the workaround and it works just like in bash :)
However, zsh devs seem very quiet.

Cheers.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-01-28 17:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-25  1:37 [PATCH] git-completion: workaround zsh COMPREPLY bug Felipe Contreras
2012-01-25  7:41 ` Matthieu Moy
2012-01-25 12:16   ` Felipe Contreras
2012-01-25 22:02     ` Matthieu Moy
2012-01-28 17:18       ` Felipe Contreras
2012-01-26 22:00 ` Junio C Hamano
2012-01-27 16:33   ` Felipe Contreras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).