zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsugabubus <zsugabubus@national.shitposting.agency>
Cc: zsh-workers@zsh.org
Subject: Re: Useless assignment in _rm
Date: Sun, 21 Jun 2020 13:32:57 +0000	[thread overview]
Message-ID: <20200621133257.2c4b679d@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20200621120913.tk5caqwb3ob2r6wt@localhost>

zsugabubus wrote on Sun, 21 Jun 2020 14:09 +0200:
> It caused issues with `rm -r<TAB> anything`:
>   _rm:72: line: assignment to invalid subscript range
>   _rm:72: line: assignment to invalid subscript range
> 

CURRENT is 0 at that point which causes the error.  In «rm -r<TAB> -f
foo», CURRENT gets set to -1.

I suppose anything that uses «*::…» or «*:::…» should verify that
CURRENT is >=1 before using it?

> As much as I understand, the assignment is not needed because in the
> next line the whole array will be reassigned.

That's not quite right: the assignment uses $line.  The patch causes
«rm foo<TAB>» when foo and foobar both exist to complete foobar;
without the patch the completion is considered ambiguous.

> diff --git a/Completion/Unix/Command/_rm b/Completion/Unix/Command/_rm
> index ea9190d..82b382b 100644
> --- a/Completion/Unix/Command/_rm
> +++ b/Completion/Unix/Command/_rm
> @@ -69,7 +69,6 @@ _arguments -C -s -S $opts \
> 
>  case $state in
>    (file)
> -    line[CURRENT]=()
>      line=( ${line//(#m)[\[\]()\\*?#<>~\^\|]/\\$MATCH} )
>      _files -F line && ret=0
>      ;;

Possible further improvements here: use ${(b)} in the assignment and
use the «zstyle … ignore-line other» functionality rather than reinvent it.

However, as above, I think the fix to the bug is just to check CURRENT.

Cheers,

Daniel

  reply	other threads:[~2020-06-21 13:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-21 12:09 zsugabubus
2020-06-21 13:32 ` Daniel Shahaf [this message]
2020-06-22 10:27   ` zsugabubus
2020-06-23 12:40     ` Daniel Shahaf
2020-06-28 13:13       ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200621133257.2c4b679d@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    --cc=zsugabubus@national.shitposting.agency \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).