Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Useless assignment in _rm
- X-seq: zsh-workers 46090
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsugabubus <zsugabubus@national.shitposting.agency>
- Subject: Re: Useless assignment in _rm
- Date: Sun, 21 Jun 2020 13:32:57 +0000
- Cc: zsh-workers@xxxxxxx
- In-reply-to: <20200621120913.tk5caqwb3ob2r6wt@localhost>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20200621120913.tk5caqwb3ob2r6wt@localhost>
- Sender: zsh-workers@xxxxxxx
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author