Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

rm *: waiting



-----BEGIN PGP SIGNED MESSAGE-----

This patch adds a new option, RM_STAR_WAIT, that causes zsh to wait ten
seconds before accepting any input at the "sure you want to delete all
files?" prompt.  This was suggested to me after a friend accidentally
did `rm *' in his home directory and reflexively typed `y' at the query.
(To make matters worse, he has GLOB_DOTS set.)

I also fixed the method by which pending input is purged; "fflush(stdin)"
is undefined.

 -zefram

 *** Doc/Zsh/options.yo	1997/01/29 03:24:53	1.7
 --- Doc/Zsh/options.yo	1997/03/17 13:51:29
 ***************
 *** 709,714 ****
 --- 709,724 ----
   item(tt(RM_STAR_SILENT) (tt(-H)))(
   Do not query the user before executing `tt(rm *)' or `tt(rm path/*)'.
   )
 + pindex(RM_STAR_WAIT)
 + cindex(rm *, waiting before)
 + cindex(waiting before rm *)
 + item(tt(RM_STAR_WAIT))(
 + If querying the user before executing `tt(rm *)' or `tt(rm path/*)',
 + first wait ten seconds and ignore anything typed in that time.
 + This avoids the problem of reflexively answering `yes' to the query
 + when one didn't really mean it.  The wait and query can always be
 + avoided by expanding the `tt(*)' in ZLE (with tab).
 + )
   pindex(SH_FILE_EXPANSION)
   cindex(sh, expansion style)
   cindex(expansion style, sh)
 *** Src/builtin.c	1997/03/17 00:38:04	1.61
 --- Src/builtin.c	1997/03/17 14:11:56
 ***************
 *** 2896,2902 ****
   	readbuf[1] = '\0';
   
   	/* get, and store, reply */
 ! 	readbuf[0] = ((char)getquery(NULL)) == 'y' ? 'y' : 'n';
   
   	/* dispose of result appropriately, etc. */
   	if (haso) {
 --- 2896,2902 ----
   	readbuf[1] = '\0';
   
   	/* get, and store, reply */
 ! 	readbuf[0] = ((char)getquery(NULL, 0)) == 'y' ? 'y' : 'n';
   
   	/* dispose of result appropriately, etc. */
   	if (haso) {
 *** Src/options.c	1997/01/29 03:25:21	1.5
 --- Src/options.c	1997/03/17 13:46:46
 ***************
 *** 156,161 ****
 --- 156,162 ----
   {NULL, "recexact",	      0,			 RECEXACT},
   {NULL, "restricted",	      OPT_SPECIAL,		 RESTRICTED},
   {NULL, "rmstarsilent",	      OPT_BOURNE,		 RMSTARSILENT},
 + {NULL, "rmstarwait",	      0,			 RMSTARWAIT},
   {NULL, "shfileexpansion",     OPT_EMULATE|OPT_BOURNE,	 SHFILEEXPANSION},
   {NULL, "shglob",	      OPT_EMULATE|OPT_BOURNE,	 SHGLOB},
   {NULL, "shinstdin",	      OPT_SPECIAL,		 SHINSTDIN},
 *** Src/utils.c	1997/03/17 00:38:11	1.65
 --- Src/utils.c	1997/03/17 14:12:05
 ***************
 *** 1046,1067 ****
   int
   checkrmall(char *s)
   {
 -     fflush(stdin);
       fprintf(shout, "zsh: sure you want to delete all the files in ");
       if (*s != '/') {
   	nicezputs(pwd[1] ? unmeta(pwd) : "", shout);
   	fputc('/', shout);
       }
       nicezputs(s, shout);
       fputs(" [yn]? ", shout);
       fflush(shout);
       beep();
 !     return (getquery("ny") == 'y');
   }
   
   /**/
   int
 ! getquery(char *valid_chars)
   {
       char c, d;
       int isem = !strcmp(term, "emacs");
 --- 1046,1073 ----
   int
   checkrmall(char *s)
   {
       fprintf(shout, "zsh: sure you want to delete all the files in ");
       if (*s != '/') {
   	nicezputs(pwd[1] ? unmeta(pwd) : "", shout);
   	fputc('/', shout);
       }
       nicezputs(s, shout);
 +     if(isset(RMSTARWAIT)) {
 + 	fputs("? (waiting ten seconds)", shout);
 + 	fflush(shout);
 + 	beep();
 + 	sleep(10);
 + 	fputc('\n', shout);
 +     }
       fputs(" [yn]? ", shout);
       fflush(shout);
       beep();
 !     return (getquery("ny", 1) == 'y');
   }
   
   /**/
   int
 ! getquery(char *valid_chars, int purge)
   {
       char c, d;
       int isem = !strcmp(term, "emacs");
 ***************
 *** 1076,1082 ****
   
   #ifdef FIONREAD
       ioctl(SHTTY, FIONREAD, (char *)&val);
 !     if (val) {
   	if (!isem)
   	    settyinfo(&shttyinfo);
   	write(SHTTY, "n\n", 2);
 --- 1082,1091 ----
   
   #ifdef FIONREAD
       ioctl(SHTTY, FIONREAD, (char *)&val);
 !     if(purge) {
 ! 	while(val--)
 ! 	    read(SHTTY, &c, 1);
 !     } else if (val) {
   	if (!isem)
   	    settyinfo(&shttyinfo);
   	write(SHTTY, "n\n", 2);
 ***************
 *** 1248,1254 ****
   	    free(pptbuf);
   	    fflush(shout);
   	    beep();
 ! 	    x = getquery("nyae ");
   	} else
   	    x = 'y';
   	if (x == 'y' || x == ' ') {
 --- 1257,1263 ----
   	    free(pptbuf);
   	    fflush(shout);
   	    beep();
 ! 	    x = getquery("nyae ", 0);
   	} else
   	    x = 'y';
   	if (x == 'y' || x == ' ') {
 *** Src/zsh.h	1997/03/17 00:38:13	1.46
 --- Src/zsh.h	1997/03/17 13:44:37
 ***************
 *** 1055,1060 ****
 --- 1055,1061 ----
       RECEXACT,
       RESTRICTED,
       RMSTARSILENT,
 +     RMSTARWAIT,
       SHFILEEXPANSION,
       SHGLOB,
       SHINSTDIN,

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii

iQCVAwUBMy1TFnD/+HJTpU/hAQG0+gP/cSqtASIyJ/b1fTyu6dw8ilq6bi3Rm748
92ID9DUT4y0Ra2aaWBZVEKiK2BPWz5qjDlNvjxmkVR8yUPn0j6/fTpqJtHHQ+C33
eDqvdK343t1z+l6AvMRt/kMP/gOEn47PfsyY52/z8hdpS42TWnPdb74krrMlPglS
xMYVTMCUIm0=
=XiOG
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author