Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh detects rm * but not rm ** (multiple stars)
- X-seq: zsh-users 18608
- From: Amm <ammdispose-zsh@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: zsh detects rm * but not rm ** (multiple stars)
- Date: Fri, 14 Mar 2014 11:18:33 +0530
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1394776115; bh=xZq6KYPZwGTeMYrif/QP+PlsunRLYWEaOrCKAt0EPE0=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:X-Rocket-Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type; b=PI5+9pk+93zdwe6Lsp+QmZcpjk4wCtdzmJy7u4MHixw6ytNOAJrffGApNZnPKifzb28CFkmGoHdyXQqGL95BgqtFE5iIXC6kq3c/A5Qb5QoIhrBYAWJqHQ7MbuHutw4rYdBcCHsKZg+yjlTq5i8UIJTYY4WNShoNZgpjzbaRH+Y=
- In-reply-to: <140313091942.ZM14393@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1394702788.77938.YahooMailNeo@web194601.mail.sg3.yahoo.com> <140313091942.ZM14393@torch.brasslantern.com>
On 03/13/2014 09:49 PM, Bart Schaefer wrote:
On Mar 13, 5:26pm, Amm wrote:
} Subject: zsh detects rm * but not rm ** (multiple stars)
}
} But I suppose match should not just be on single *
} but on *+ (1 or more *)
Thanks for the suggestion. The "rm *" behavior is very old (was in
the shell even before the special meaning of "**", something over 20
years ago now) and hasn't changed in all that time, so I can't say
with any confidence it'll change now.
Umm, I think it should be changed.
I have tried to fix this. I have attached a patch to exec.c file,
Patch is very small. It does not change logic. Just extends the check to
checkriskyglob() function.
Currently checkriskyglob() checks for glob containing / and *.
So it will match / OR */ OR **/ OR */* OR **/* OR **/** so on
In future it may be extended to check other patterns which can cause
accidental destruction.
} Also is there a way to make zsh warn when there is * in
} argument list, regardless of command?
I think most people would just find this annoying :-)
I doubt it would be annoying because:
1) I dont think good administrator would ever use * directly for any
command (Its better to be very specific by simply pressing *<TAB> -
which will expand star to ALL files)
2) If one still feels annoyed then just like RM_STAR_SILENT|WAIT we can
add CMD_STAR_SILENT/WAIT.
Only difference is that CMD_STAR_SILENT would be enabled by default and
CMD_STAR_WAIT would be disabled by default.
So existing behaviour will continue by default but anyone who wants
functionality I wanted, can activate accordingly.
This behaves the way you wanted, aborting the entire command on any
"no" answer (but leaving it in the editor for you to fix, which you
didn't ask for but seemed reasonable).
Great thanks a lot. You have always been of great help.
Amm
--- exec.c.old 2014-03-14 10:31:32.071645866 +0530
+++ exec.c 2014-03-14 10:53:35.616798543 +0530
@@ -2351,6 +2351,18 @@
}
/**/
+static int
+checkriskyglob(const char *s)
+{
+ if (!s) return 0;
+ while (s[0] == Star || s[0] == '/') {
+ if (!s[1]) return 1;
+ ++s;
+ }
+ return 0;
+}
+
+/**/
static void
execcmd(Estate state, int input, int output, int how, int last1)
{
@@ -2729,20 +2741,18 @@
LinkNode node, next;
for (node = nextnode(firstnode(args)); node && !errflag; node = next) {
- char *s = (char *) getdata(node);
+ char *rs, *s = (char *) getdata(node);
int l = strlen(s);
next = nextnode(node);
- if (s[0] == Star && !s[1]) {
+ if (checkriskyglob(s)) {
if (!checkrmall(pwd))
uremnode(args, node);
- } else if (l > 2 && s[l - 2] == '/' && s[l - 1] == Star) {
- char t = s[l - 2];
-
- s[l - 2] = 0;
+ } else if (l > 2 && (rs = strrchr(l, '/')) && checkriskyglob(rs+1)) {
+ *rs = 0;
if (!checkrmall(s))
uremnode(args, node);
- s[l - 2] = t;
+ *rs = '/';
}
}
if (!nextnode(firstnode(args)))
Messages sorted by:
Reverse Date,
Date,
Thread,
Author