From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5263 invoked from network); 17 Mar 1997 18:31:42 -0000 Received: from euclid.skiles.gatech.edu (list@130.207.146.50) by coral.primenet.com.au with SMTP; 17 Mar 1997 18:31:42 -0000 Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id NAA00524; Mon, 17 Mar 1997 13:16:17 -0500 (EST) Resent-Date: Mon, 17 Mar 1997 13:16:17 -0500 (EST) Date: Mon, 17 Mar 1997 18:18:55 GMT From: Zefram Message-Id: <5273.199703171818@stone.dcs.warwick.ac.uk> Subject: rm *: waiting X-Patch: 206 Resent-Message-ID: <"x04lZ2.0.78.mfOBp"@euclid> To: zsh-workers@math.gatech.edu Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2999 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----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-----