From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23996 invoked by alias); 30 Jun 2014 11:43:36 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32822 Received: (qmail 17690 invoked from network); 30 Jun 2014 11:43:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Biglobe-Sender: Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: [Pkg-zsh-devel] Bug#679824: zsh: Buggy perl completion with -e [origin: vincent@vinc17.net] From: "Jun T." In-Reply-To: <20140628142003.GI5355@sym.noone.org> Date: Mon, 30 Jun 2014 19:58:26 +0900 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20140628142003.GI5355@sym.noone.org> To: "zsh-workers@zsh.org" X-Mailer: Apple Mail (2.1510) X-Biglobe-Spnum: 49760 On 2014/06/28, at 23:20, Axel Beckert wrote: > $ perl -pi -e 's/foo/bar/' [TAB] >=20 > zsh wants to complete on Perl scripts instead of normal files. > AFAIK, after -e '...', completion should be done on arbitrary > arguments (e.g. like after an unknown command). I first thought that just replacing the line 19 of _perl '( -E)*-e+[run one line of program]:one line of program' \ by '(1 -E)*-e+[run one line of program]:one line of program' \ would be enough, but it didn't work. For example perl -e 's/foo/bar/' will offer all the command names (external commands etc.), instead of the file names in the current directory. This is because the '::' in line 44 '*::args: _normal' will clear the array $words, and the completion system thinks that it is completing at the beginning of the command line and will try to complete a command name. But this '::' can't be simply replaced by ':' (infinite recursion will happen). A possible fix would be to modify the completion of the 1st argument if -e '...' is already on the command line (see the patch bellow). But detecting -e '...' (or -E '...') is rather complicated, because perl allows command lines like perl -pes/foo/bar/ arg ... perl -CE script_file arg ... I'm not sure the following patch is 100% OK (I'm not familiar with most of the perl command line options). Another possibility would be to modify line 19 (and 20) as above, and modify line 44 to '*:args: _files' I guess this may reduce the possibility of user customization of the completion, but I have no idea how serious it is. diff --git a/Completion/Unix/Command/_perl = b/Completion/Unix/Command/_perl index b00baa6..1939cb0 100644 --- a/Completion/Unix/Command/_perl +++ b/Completion/Unix/Command/_perl @@ -40,10 +40,21 @@ _perl () { "(-w -X)-W[enable all warnings (ignores 'no warnings')]" \ "(-w -W )-X[disable all warnings (ignores 'use warnings')]" \ '-x-[strip off text before #!perl line and perhaps cd to = directory]:directory to cd to:_files -/' \ - '1:Perl script:_files -/ -g "*.(p[ml]|PL|t)(-.)"' \ + '1:script or args:_script_or_args' \ '*::args: _normal' } =20 +_script_or_args () { + local expl + if (( $words[(I)-(e|E)*] )); then + _description args expl 'file' + _files "$expl[@]" + else + _description script expl 'Perl script' + _files "$expl[@]" -/ -g "*.(p[ml]|PL|t)(-.)" + fi +} + _perl_m_opt () { compset -P '-' =20