From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19222 invoked by alias); 10 Feb 2016 16:41:58 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37938 Received: (qmail 28146 invoked from network); 10 Feb 2016 16:41:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_HDRS_LCASE, T_MANY_HDRS_LCASE autolearn=ham autolearn_force=no version=3.4.1 X-AuditID: cbfec7f4-f79026d00000418a-a5-56bb68512366 Date: Wed, 10 Feb 2016 16:41:50 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: rm * with count Message-id: <20160210164150.5bef82b2@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKLMWRmVeSWpSXmKPExsVy+t/xK7qBGbvDDJ6f5rQ42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGQu/z2UvOMZZ0blrD1MD41T2LkYODgkBE4l5v9K6GDmBTDGJ C/fWs3UxcnEICSxllPjfc4oZwpnBJHF5WycjhHOOUeLsm29QmbOMEkfWfwcbxSKgKnG6Vwhk FJuAocTUTbMZQcIiAtoS7R/FQMLCAvISm06fYQUJ8wrYSzRtcAAJ8wvoS1z9+4kJ4gh7iZlX zjCC2LwCghI/Jt9jAbGZBbQkNm9rYoWw5SU2r3nLDGILCahL3Li7m30Co+AsJC2zkLTMQtKy gJF5FaNoamlyQXFSeq6hXnFibnFpXrpecn7uJkZIYH7Zwbj4mNUhRgEORiUe3hsmu8KEWBPL iitzDzFKcDArifCuj98dJsSbklhZlVqUH19UmpNafIhRmoNFSZx37q73IUIC6YklqdmpqQWp RTBZJg5OqQbGRVMFQzf1huxLeieqLHxs1nH2xRZ6uRH5E3OlZCp4WUyK5rAu7dnfuLJ6cbvL xuAzf1z8GnZeEZF8EFU5Z/F/xecRnLXnjv5PsKoRXcEv8/u+uM6F1G99YSWWMuVW0tpvyt3S lik4nTzRl1XuufdlL/PdVQf0efJnbWfdw2H8fdJ322sMq7iUWIozEg21mIuKEwEAn+/gSAIA AA== 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);