Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Useless assignment in _rm



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