Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Useless assignment in _rm
- X-seq: zsh-workers 46097
- From: zsugabubus <zsugabubus@national.shitposting.agency>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Subject: Re: Useless assignment in _rm
- Date: Mon, 22 Jun 2020 12:27:38 +0200
- Cc: zsh-workers@xxxxxxx
- In-reply-to: <20200621133257.2c4b679d@tarpaulin.shahaf.local2>
- 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> <20200621133257.2c4b679d@tarpaulin.shahaf.local2>
- Sender: zsh-workers@xxxxxxx
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