Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: rm * with count
- X-seq: zsh-workers 37938
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: Zsh Hackers' List <zsh-workers@xxxxxxx>
- Subject: PATCH: rm * with count
- Date: Wed, 10 Feb 2016 16:41:50 +0000
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
Faced with a "rm *" prompt, it occurred to me it might be a little bit
more helpful to decide if something has gone really horribly wrong if we
made the easy tweak to count the number of files in the directory.
Any comments on the following?
pws
diff --git a/Src/utils.c b/Src/utils.c
index de4af5a..362bd17 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2634,13 +2634,27 @@ zsleep_random(long max_us, time_t end_time)
int
checkrmall(char *s)
{
+ DIR *rmd;
+ int count = 0;
if (!shout)
return 1;
- fprintf(shout, "zsh: sure you want to delete all the files in ");
if (*s != '/') {
- nicezputs(pwd[1] ? pwd : "", shout);
- fputc('/', shout);
+ if (pwd[1])
+ s = zhtricat(pwd, "/", s);
+ else
+ s = dyncat("/", s);
+ }
+ if ((rmd = opendir(unmeta(s)))) {
+ int ignoredots = !isset(GLOBDOTS);
+ while (zreaddir(rmd, ignoredots))
+ count++;
+ closedir(rmd);
}
+ if (count > 0)
+ fprintf(shout, "zsh: sure you want to delete all %d files in ",
+ count);
+ else
+ fprintf(shout, "zsh: sure you want to delete all the files in ");
nicezputs(s, shout);
if(isset(RMSTARWAIT)) {
fputs("? (waiting ten seconds)", shout);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author