{"thread":{"id":"29442","subject":"[PATCH] git-completion: workaround zsh COMPREPLY bug","startedAt":"2012-01-25T01:37:02Z","lastAt":"2012-01-28T17:18:07Z","messageCount":7,"participants":["Felipe Contreras","Matthieu Moy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"183058","messageId":"1327455422-22340-1-git-send-email-felipe.contreras@gmail.com","threadId":"29442","inReplyTo":null,"subject":"[PATCH] git-completion: workaround zsh COMPREPLY bug","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-25T01:37:02Z","receivedAt":"2012-01-25T01:37:02Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"zsh adds a backslash (foo\\ ) for each item in the COMPREPLY array if IFS\ndoesn't contain spaces. This issue has been reported[1], but there is no\nsolution yet.\n\nThis wasn't a problem due to another bug[2], which was fixed in zsh\nversion 4.3.12. After this change, 'git checkout ma<tab>' would resolve\nto 'git checkout master\\ '.\n\nAditionally, the introduction of __gitcomp_nl in commit a31e626\n(completion: optimize refs completion) in git also made the problem\napparent, as Matthieu Moy reported.\n\nThe simplest and most generic solution is to hide all the changes we do\nto IFS, so that \"foo \\nbar \" is recognized by zsh as \"foo bar\". This\nworks on versions of git before and after the introduction of\n__gitcomp_nl (a31e626), and versions of zsh before and after 4.3.12.\n\nOnce zsh is fixed, we should conditionally disable this workaround to\nhave the same benefits as bash users.\n\n[1] http://www.zsh.org/mla/workers/2012/msg00053.html\n[2] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex b0062ba..c83c734 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2631,6 +2631,10 @@ _git ()\n \t\t# workaround zsh's bug that leaves 'words' as a special\n \t\t# variable in versions < 4.3.12\n \t\ttypeset -h words\n+\n+\t\t# another workaround for zsh because it would quote spaces in\n+\t\t# the COMPREPLY array if IFS doesn't contain spaces\n+\t\ttypeset -h IFS\n \tfi\n \n \tlocal cur words cword prev\n@@ -2687,6 +2691,10 @@ _gitk ()\n \t\t# workaround zsh's bug that leaves 'words' as a special\n \t\t# variable in versions < 4.3.12\n \t\ttypeset -h words\n+\n+\t\t# another workaround for zsh because it would quote spaces in\n+\t\t# the COMPREPLY array if IFS doesn't contain spaces\n+\t\ttypeset -h IFS\n \tfi\n \n \tlocal cur words cword prev\n-- \n1.7.8.rc1.14.g248db\n"},{"id":"183072","messageId":"vpqwr8g8c03.fsf@bauges.imag.fr","threadId":"29442","inReplyTo":"1327455422-22340-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] git-completion: workaround zsh COMPREPLY bug","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-01-25T07:41:48Z","receivedAt":"2012-01-25T07:41:48Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> The simplest and most generic solution is to hide all the changes we do\n> to IFS, so that \"foo \\nbar \" is recognized by zsh as \"foo bar\". This\n> works on versions of git before and after the introduction of\n> __gitcomp_nl (a31e626), and versions of zsh before and after 4.3.12.\n[...]\n> +\n> +\t\t# another workaround for zsh because it would quote spaces in\n> +\t\t# the COMPREPLY array if IFS doesn't contain spaces\n> +\t\ttypeset -h IFS\n\nNo time to test right now, but is this not going to\n\n1) leave IFS as hidden even outside the completion script, possibly\naffecting unrelated scripts that would need to set IFS as local and keep\nits special effect?\n\n2) break cases where strings are to be split on \\n only (e.g. see\n\"foo bar\\nboz\" as three possible completions \"foo\", \"bar\", \"boz\" instead\nof \"foo bar\" and \"boz\"?\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"183078","messageId":"CAMP44s16L0GJUh4JcQgjBXUf4ftT7yQFgPy0p6zCNMnZjZGQww@mail.gmail.com","threadId":"29442","inReplyTo":"vpqwr8g8c03.fsf@bauges.imag.fr","subject":"Re: [PATCH] git-completion: workaround zsh COMPREPLY bug","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-25T12:16:53Z","receivedAt":"2012-01-25T12:16:53Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, Jan 25, 2012 at 9:41 AM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n>> The simplest and most generic solution is to hide all the changes we do\n>> to IFS, so that \"foo \\nbar \" is recognized by zsh as \"foo bar\". This\n>> works on versions of git before and after the introduction of\n>> __gitcomp_nl (a31e626), and versions of zsh before and after 4.3.12.\n> [...]\n>> +\n>> +             # another workaround for zsh because it would quote spaces in\n>> +             # the COMPREPLY array if IFS doesn't contain spaces\n>> +             typeset -h IFS\n>\n> No time to test right now, but is this not going to\n>\n> 1) leave IFS as hidden even outside the completion script, possibly\n> affecting unrelated scripts that would need to set IFS as local and keep\n> its special effect?\n\nWhat special effect?\n\nUnrelated scripts can still set IFS as local.\n\nYou can test this:\n\n---\n#!/bin/sh\n\nif [[ -n ${ZSH_VERSION-} ]]; then\n    autoload -U +X bashcompinit && bashcompinit\nfi\n\n_foo()\n{\n    typeset -h IFS\n    local cur=\"${COMP_WORDS[COMP_CWORD]}\"\n    local IFS=$'\\n'\n    w[0]='first '\n    w[1]='second and space '\n    w[2]='third\\\\ quoted\\\\ space '\n    ./test1 >> /tmp/t1.txt\n    COMPREPLY=( $(compgen -W \"${w[*]}\" -- $cur) )\n}\ncomplete -o nospace -F _foo foo\n---\n\ntest1:\n---\n#!/bin/sh\n\ntest1() {\n\tlocal IFS=$'\\n'\n\tw=( $(echo -e \"foo \\nbar\"))\n\techo \"test1: 0:'${w[0]}' 1:'${w[1]}'\"\n}\n\ntest1\n\nw=( $(echo -e \"foo \\nbar\"))\necho \"test2: 0:'${w[0]}' 1:'${w[1]}'\"\n---\n\nThe result in /tmp/t1.txt would be:\ntest1: 0:'foo ' 1:'bar'\ntest2: 0:'foo' 1:'bar'\n\nRegardless of whether you use typeset -h or not.\n\n> 2) break cases where strings are to be split on \\n only (e.g. see\n> \"foo bar\\nboz\" as three possible completions \"foo\", \"bar\", \"boz\" instead\n> of \"foo bar\" and \"boz\"?\n\nThose cases are already broken, which is what I reported to the zsh\nmailing list. You would get \"foo\\ bar\" and \"boz\", and that's after\n4.3.12; before, compgen -W would still break the completions in 3,\nbecause they did 'results+=( $words )', instead of 'results+=(\n\"$words\" )'.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"183097","messageId":"vpqr4ynzbj7.fsf@bauges.imag.fr","threadId":"29442","inReplyTo":"CAMP44s16L0GJUh4JcQgjBXUf4ftT7yQFgPy0p6zCNMnZjZGQww@mail.gmail.com","subject":"Re: [PATCH] git-completion: workaround zsh COMPREPLY bug","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-01-25T22:02:04Z","receivedAt":"2012-01-25T22:02:04Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n>>> +             typeset -h IFS\n>>\n>> No time to test right now, but is this not going to\n>>\n>> 1) leave IFS as hidden even outside the completion script, possibly\n>> affecting unrelated scripts that would need to set IFS as local and keep\n>> its special effect?\n>\n> What special effect?\n>\n> Unrelated scripts can still set IFS as local.\n\nOK, I missed the fact that typeset -h had only local effect.\n\n>> 2) break cases where strings are to be split on \\n only (e.g. see\n>> \"foo bar\\nboz\" as three possible completions \"foo\", \"bar\", \"boz\" instead\n>> of \"foo bar\" and \"boz\"?\n>\n> Those cases are already broken, which is what I reported to the zsh\n> mailing list. You would get \"foo\\ bar\" and \"boz\", and that's after\n> 4.3.12; before, compgen -W would still break the completions in 3,\n> because they did 'results+=( $words )', instead of 'results+=(\n> \"$words\" )'.\n\nMakes sense.\n\nI still have a minor comment: maybe part of your commit message could go\nto a comment in the code as well, in particular the \"Once zsh is fixed\"\npart, to help future contributors to actually disable the workaround\nwhen possible in the future.\n\nTested-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"183135","messageId":"7v4nvi2kgq.fsf@alter.siamese.dyndns.org","threadId":"29442","inReplyTo":"1327455422-22340-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] git-completion: workaround zsh COMPREPLY bug","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-01-26T22:00:05Z","receivedAt":"2012-01-26T22:00:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> zsh adds a backslash (foo\\ ) for each item in the COMPREPLY array if IFS\n> doesn't contain spaces. This issue has been reported[1], but there is no\n> solution yet.\n> ...\n> Once zsh is fixed, we should conditionally disable this workaround to\n> have the same benefits as bash users.\n>\n> [1] http://www.zsh.org/mla/workers/2012/msg00053.html\n> [2] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d\n\nThat 2e25dfb8 only says:\n\n    Rocky Bernstein: 29135 (plus tweaks): compgen -W in bash completion\n\nwithout any explanation, which is not very useful.\n\nDo you have a bug tracker ID or something for [1] above, with which I can\namend the patch as Matthieu suggests?\n"},{"id":"183191","messageId":"CAMP44s1hdFDfs=a-3XNCYpLUqGw4rq5spsO6qesvP5sp-A1fJw@mail.gmail.com","threadId":"29442","inReplyTo":"7v4nvi2kgq.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git-completion: workaround zsh COMPREPLY bug","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-27T16:33:50Z","receivedAt":"2012-01-27T16:33:50Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Jan 27, 2012 at 12:00 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n>> zsh adds a backslash (foo\\ ) for each item in the COMPREPLY array if IFS\n>> doesn't contain spaces. This issue has been reported[1], but there is no\n>> solution yet.\n>> ...\n>> Once zsh is fixed, we should conditionally disable this workaround to\n>> have the same benefits as bash users.\n>>\n>> [1] http://www.zsh.org/mla/workers/2012/msg00053.html\n>> [2] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d\n>\n> That 2e25dfb8 only says:\n>\n>    Rocky Bernstein: 29135 (plus tweaks): compgen -W in bash completion\n>\n> without any explanation, which is not very useful.\n\nYeah, they development practices leaves a lot to be desired.\n\n> Do you have a bug tracker ID or something for [1] above, with which I can\n> amend the patch as Matthieu suggests?\n\nI don't think there's something like that, but here's the original discussion:\n\nhttp://thread.gmane.org/gmane.comp.shells.zsh.devel/22541\n\n-- \nFelipe Contreras\n"},{"id":"183223","messageId":"CAMP44s27i=5iX9Dr+TmOLKaAa0=TC-JwED5WuiDguBuBbfMEhQ@mail.gmail.com","threadId":"29442","inReplyTo":"vpqr4ynzbj7.fsf@bauges.imag.fr","subject":"Re: [PATCH] git-completion: workaround zsh COMPREPLY bug","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-28T17:18:07Z","receivedAt":"2012-01-28T17:18:07Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Jan 26, 2012 at 12:02 AM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> I still have a minor comment: maybe part of your commit message could go\n> to a comment in the code as well, in particular the \"Once zsh is fixed\"\n> part, to help future contributors to actually disable the workaround\n> when possible in the future.\n\nFTR, I've fixed all the issues in zsh's bash completion:\n\nhttp://thread.gmane.org/gmane.comp.shells.zsh.devel/24290\n\nNow I don't need the workaround and it works just like in bash :)\nHowever, zsh devs seem very quiet.\n\nCheers.\n\n-- \nFelipe Contreras\n"}]}