zsh-workers
 help / color / mirror / code / Atom feed
From: zsugabubus <zsugabubus@national.shitposting.agency>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: zsh-workers@zsh.org
Subject: Re: Useless assignment in _rm
Date: Mon, 22 Jun 2020 12:27:38 +0200	[thread overview]
Message-ID: <20200622102738.56fotlwrsbckxgzh@localhost> (raw)
In-Reply-To: <20200621133257.2c4b679d@tarpaulin.shahaf.local2>

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

  reply	other threads:[~2020-06-22 10:28 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
2020-06-22 10:27   ` zsugabubus [this message]
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=20200622102738.56fotlwrsbckxgzh@localhost \
    --to=zsugabubus@national.shitposting.agency \
    --cc=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /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).