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

Re: Useless assignment in _rm



On Sun, Jun 21, 2020 at 01:32:57PM +0000, Daniel Shahaf wrote:
> I suppose anything that uses «*::…» or «*:::…» should verify that
> CURRENT is >=1 before using it?

I searched for similar assignments and queries but I could not find
other place where an extra check would be needed.

(“$words[CURRENT]” is safe no?, because a negative number will just
index backwards so it gives the correct word; and out-of-bounds or zero
just returns nothing.)

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

You are absolutely right!!

-- 
zsugabubus

diff --git a/Completion/Unix/Command/_rm b/Completion/Unix/Command/_rm
index ea9190d..e66b77f 100644
--- a/Completion/Unix/Command/_rm
+++ b/Completion/Unix/Command/_rm
@@ -69,7 +69,7 @@ _arguments -C -s -S $opts \

 case $state in
   (file)
-    line[CURRENT]=()
+    (( CURRENT > 0 )) && line[CURRENT]=()
     line=( ${line//(#m)[\[\]()\\*?#<>~\^\|]/\\$MATCH} )
     _files -F line && ret=0
     ;;



Messages sorted by: Reverse Date, Date, Thread, Author