From unknown Sun Jun 22 22:46:33 2025 X-Loop: help-debbugs@gnu.org Subject: bug#27496: 26.0.50; dired-do-shell-command just checks the first wildcard Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 26 Jun 2017 10:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27496 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 27496@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.149847393628270 (code B ref -1); Mon, 26 Jun 2017 10:46:02 +0000 Received: (at submit) by debbugs.gnu.org; 26 Jun 2017 10:45:36 +0000 Received: from localhost ([127.0.0.1]:38057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPRWR-0007Lu-Uz for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53810) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPRWQ-0007Lh-3U for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPRWJ-0002iq-HH for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:28 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:55381) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dPRWJ-0002ik-Dh for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPRWH-0003mJ-TM for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPRWD-0002h7-Vb for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:25 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:34960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPRWD-0002gP-OM for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:21 -0400 Received: by mail-pf0-x244.google.com with SMTP id s66so17595211pfs.2 for ; Mon, 26 Jun 2017 03:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:from:to:subject; bh=xOfgrIrj/1b6noUy9znzZLJJWG+k8yF44AGvTuqODtY=; b=Btl5aoxlQaUvQkSFdY44iBLIYsNoabFdBEO/XGMwaT/5vZhvtDxVTFwVbha/OPbr4w cOsklD/dSDjQdlGi+Y36ergkO3lrKTJXMDHpqyJvJYMLMTm9ry3P8NUuGqB53FaZFGUG QsFOuaf/ibtdpVv8m3fK8ZGLeq8dMPBNxMPKO4pM/xr5K6cP8L5o0JsuvkzKrxig9JRd fiX/2lEbNVZ2eHDKfepvKYq2kk4V/r+NEPqWUHGmPMxMAN4eVXhNc8UJB/9tyLRU7OmE cDv8gWU+tHmzCAxS3L6Z2dZMW4B3N2D2OAffNIlKUcogn1Yb8MiWLtRozZjWEotM0OPR /hIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:from:to:subject; bh=xOfgrIrj/1b6noUy9znzZLJJWG+k8yF44AGvTuqODtY=; b=ac9lkrpSmRmOZYOEQlTh2beSfQaAJv2UeqJp1D7MBpB0RKhvjl0pYaL9LjY4KRPo0a sSt+wmRwJQKXldpocOR4Ssat0ZrsdhbkR1zglZBAT9RYDkvK0gHzTRIi5myZfWSnY2HK Iu4fbg1bcEghNKj8MN8TJZwuBXHQuGNs7I0ULffE5/l6GgCeUDWLhA8vHDTMm9H8KWNy FxDkBsw+BPguCKDJNWwqBXh3gWLu+0SIub5vpMQ/e5lhRSQe7qdowpBBYBZIjwakoF2S wBkThtLIOlhgvfmtOC1DD5Rju+nVGVH4L1mthI3Be0mI+KLHbmdvsnchaKa0RhnGudm/ 6rCg== X-Gm-Message-State: AKS2vOygG8ftIIWv8NPPsyngALusHNIV0vIFoUu5gQowPLbw+E0Vgdne aAsRJyo8x+IWLfqA X-Received: by 10.98.150.157 with SMTP id s29mr20780155pfk.172.1498473919014; Mon, 26 Jun 2017 03:45:19 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id e189sm21280130pfe.100.2017.06.26.03.45.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2017 03:45:18 -0700 (PDT) Date: Mon, 26 Jun 2017 19:45:13 +0900 Message-Id: <87fuen58p2.fsf@calancha-pc> From: Tino Calancha X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) Severity: minor Tags: patch emacs -Q: ;; Evaluate following form. (let ((foo (make-temp-file "foo" 'dir)) (bar (make-temp-file "bar" 'dir))) (dired foo) (dired-up-directory) (revert-buffer) (dired-do-shell-command (format "cp -r ? %s/?" bar) nil (dired-get-marked-files t nil))) ;; Should ask confirmation because "/?". If we change the last line to: (format "cp -r ./? %s/?" bar) nil (dired-get-marked-files t nil))) then it asks confirmation because "./?". --8<-----------------------------cut here---------------start------------->8--- commit dd809606eefea96a034eb4fe8da237003321ffd3 Author: Tino Calancha Date: Mon Jun 26 19:16:57 2017 +0900 Ask confirmation for all suspicious wildcards * lisp/dired-aux.el (dired-do-shell-command): Check that all the wildcards are right. Otherwise, ask fo confirmation (Bug#27496). diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 121bebeb65..f257a454f9 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -704,31 +704,41 @@ dired-do-shell-command (dired-read-shell-command "! on %s: " current-prefix-arg files) current-prefix-arg files))) - (let* ((on-each (not (string-match-p dired-star-subst-regexp command))) - (no-subst (not (string-match-p dired-quark-subst-regexp command))) - (star (string-match-p "\\*" command)) - (qmark (string-match-p "\\?" command)) - ;; Get confirmation for wildcards that may have been meant - ;; to control substitution of a file name or the file name list. - (ok (cond ((not (or on-each no-subst)) - (error "You can not combine `*' and `?' substitution marks")) - ((and star on-each) - (y-or-n-p (format-message - "Confirm--do you mean to use `*' as a wildcard? "))) - ((and qmark no-subst) - (y-or-n-p (format-message - "Confirm--do you mean to use `?' as a wildcard? "))) - (t)))) - (when ok - (if on-each - (dired-bunch-files (- 10000 (length command)) - (lambda (&rest files) - (dired-run-shell-command - (dired-shell-stuff-it command files t arg))) - nil file-list) - ;; execute the shell command - (dired-run-shell-command - (dired-shell-stuff-it command file-list nil arg)))))) + (cl-flet ((need-confirm-p + (cmd str) + (let ((res cmd) + (str (regexp-quote str)) + (regexp (if (string= str "?") + dired-quark-subst-regexp + dired-star-subst-regexp))) + ;; Drop all ? and * surrounded by spaces. + (while (and (string-match-p str res) + (string-match regexp res)) + (setq res (replace-match "" t t res 0))) + (string-match-p str res)))) + (let* ((on-each (not (string-match-p dired-star-subst-regexp command))) + (no-subst (not (string-match-p dired-quark-subst-regexp command))) + ;; Get confirmation for wildcards that may have been meant + ;; to control substitution of a file name or the file name list. + (ok (cond ((not (or on-each no-subst)) + (error "You can not combine `*' and `?' substitution marks")) + ((need-confirm-p command "*") + (y-or-n-p (format-message + "Confirm--do you mean to use `*' as a wildcard? "))) + ((need-confirm-p command "?") + (y-or-n-p (format-message + "Confirm--do you mean to use `?' as a wildcard? "))) + (t)))) + (when ok + (if on-each + (dired-bunch-files (- 10000 (length command)) + (lambda (&rest files) + (dired-run-shell-command + (dired-shell-stuff-it command files t arg))) + nil file-list) + ;; execute the shell command + (dired-run-shell-command + (dired-shell-stuff-it command file-list nil arg))))))) ;; Might use {,} for bash or csh: (defvar dired-mark-prefix "" --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 9, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-06-26 built Repository revision: 1771d9b8082cf967e3f8b6a436d8766560be9e8d From unknown Sun Jun 22 22:46:33 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Tino Calancha Subject: bug#27496: closed (Re: bug#27496: 26.0.50; dired-do-shell-command just checks the first wildcard) Message-ID: References: <8760fbx9q9.fsf@calancha-pc> <87fuen58p2.fsf@calancha-pc> X-Gnu-PR-Message: they-closed 27496 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 27496@debbugs.gnu.org Date: Sun, 02 Jul 2017 13:14:04 +0000 Content-Type: multipart/mixed; boundary="----------=_1499001244-9410-1" This is a multi-part message in MIME format... ------------=_1499001244-9410-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #27496: 26.0.50; dired-do-shell-command just checks the first wildcard which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 27496@debbugs.gnu.org. --=20 27496: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D27496 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1499001244-9410-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 27496-done) by debbugs.gnu.org; 2 Jul 2017 13:13:48 +0000 Received: from localhost ([127.0.0.1]:48224 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRehA-0002RC-G0 for submit@debbugs.gnu.org; Sun, 02 Jul 2017 09:13:48 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:35674) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dReh8-0002Qz-9i for 27496-done@debbugs.gnu.org; Sun, 02 Jul 2017 09:13:46 -0400 Received: by mail-pf0-f169.google.com with SMTP id c73so87770503pfk.2 for <27496-done@debbugs.gnu.org>; Sun, 02 Jul 2017 06:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version; bh=4aSxAWFqHC9j1mBUmuicj+OxVBcsvjoK+1WAUaHn+8o=; b=Waa6magCrP1wMH0dHgBPJnE7PyQIVGEKG7birdXh2tZo6atR/sRjOF5iq5kP/2XnxT qmQ4mF5MamjlFV/lvRX3u5/vwIXYMUb0IQVLbEXtD6z73jnRDn/SQCqTp1eFxdydGe9l JKotSNPIj5RWIPg4D09l6GeWjMSE1QgPv3gXjxN4FnE7e4aOnrHlfdd7uRWNrv1zZNXN fby5+meXOI9wRiIqqsJk5k2AVS5iz//UIX5SWxGE1EJvH3Nl1yq37aPIKkvayiRGzuJ5 DE0TQgBWhjf2+Hh+XGEKdGtrAeL9+HAvWpch8MYaxpPP9VW058Nkf94AbiMOG+HX+J/Y /04g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=4aSxAWFqHC9j1mBUmuicj+OxVBcsvjoK+1WAUaHn+8o=; b=lp9FqNF5ZTvkNWWdfl++9sjWgbWGxdRxdaW9wlC2ZywneshczlQIs4Gf9S6xgNI1Jf 4u0JyHIdfV6Ug7dmYipQ1NK1TCtDKIBPyqOWH38b6woYPk3xMBL/XjWBVaR6E+SV7T8Z xJJNi00NlPOok8NBitPtnTwsBDoZtx0gUZWv+h+WYMID46ALJUaqyOifIKSARpKb+W7U t3WhibJZLJihI84/5LLQ+YgASjh3lWYWwoOKt1112w71XPKr4NFNld9ezZqixPAKCfrv horUcqPyDwmTYRggvwlUJq+eu2ap4ofO1kLFhzG/AtA5647G8WtOoGZxdRiBhzQtVPLT RTWQ== X-Gm-Message-State: AIVw113iS1ixUoal/NoLXni9gi0coQRjr77cgZ5o8k8eKCu2Tg0oNh2Z ZfS1FezyIQLX6zZY X-Received: by 10.98.106.6 with SMTP id f6mr5083575pfc.53.1499001220235; Sun, 02 Jul 2017 06:13:40 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id x25sm31550478pfi.58.2017.07.02.06.13.38 for <27496-done@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 02 Jul 2017 06:13:39 -0700 (PDT) From: Tino Calancha To: 27496-done@debbugs.gnu.org Subject: Re: bug#27496: 26.0.50; dired-do-shell-command just checks the first wildcard References: <87fuen58p2.fsf@calancha-pc> Date: Sun, 02 Jul 2017 22:13:34 +0900 In-Reply-To: <87fuen58p2.fsf@calancha-pc> (Tino Calancha's message of "Mon, 26 Jun 2017 19:45:13 +0900") Message-ID: <8760fbx9q9.fsf@calancha-pc> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 27496-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Tino Calancha writes: > emacs -Q: > ;; Evaluate following form. > (let ((foo (make-temp-file "foo" 'dir)) > (bar (make-temp-file "bar" 'dir))) > (dired foo) > (dired-up-directory) > (revert-buffer) > (dired-do-shell-command > (format "cp -r ? %s/?" bar) nil (dired-get-marked-files t nil))) > > ;; Should ask confirmation because "/?". > > If we change the last line to: > (format "cp -r ./? %s/?" bar) nil (dired-get-marked-files t nil))) > then it asks confirmation because "./?". Fixed in master branch as commit 6e39940adba7b96dfe520caa52a1b92a1a84a84f ------------=_1499001244-9410-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 26 Jun 2017 10:45:36 +0000 Received: from localhost ([127.0.0.1]:38057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPRWR-0007Lu-Uz for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53810) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPRWQ-0007Lh-3U for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPRWJ-0002iq-HH for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:28 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:55381) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dPRWJ-0002ik-Dh for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPRWH-0003mJ-TM for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPRWD-0002h7-Vb for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:25 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:34960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPRWD-0002gP-OM for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:21 -0400 Received: by mail-pf0-x244.google.com with SMTP id s66so17595211pfs.2 for ; Mon, 26 Jun 2017 03:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:from:to:subject; bh=xOfgrIrj/1b6noUy9znzZLJJWG+k8yF44AGvTuqODtY=; b=Btl5aoxlQaUvQkSFdY44iBLIYsNoabFdBEO/XGMwaT/5vZhvtDxVTFwVbha/OPbr4w cOsklD/dSDjQdlGi+Y36ergkO3lrKTJXMDHpqyJvJYMLMTm9ry3P8NUuGqB53FaZFGUG QsFOuaf/ibtdpVv8m3fK8ZGLeq8dMPBNxMPKO4pM/xr5K6cP8L5o0JsuvkzKrxig9JRd fiX/2lEbNVZ2eHDKfepvKYq2kk4V/r+NEPqWUHGmPMxMAN4eVXhNc8UJB/9tyLRU7OmE cDv8gWU+tHmzCAxS3L6Z2dZMW4B3N2D2OAffNIlKUcogn1Yb8MiWLtRozZjWEotM0OPR /hIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:from:to:subject; bh=xOfgrIrj/1b6noUy9znzZLJJWG+k8yF44AGvTuqODtY=; b=ac9lkrpSmRmOZYOEQlTh2beSfQaAJv2UeqJp1D7MBpB0RKhvjl0pYaL9LjY4KRPo0a sSt+wmRwJQKXldpocOR4Ssat0ZrsdhbkR1zglZBAT9RYDkvK0gHzTRIi5myZfWSnY2HK Iu4fbg1bcEghNKj8MN8TJZwuBXHQuGNs7I0ULffE5/l6GgCeUDWLhA8vHDTMm9H8KWNy FxDkBsw+BPguCKDJNWwqBXh3gWLu+0SIub5vpMQ/e5lhRSQe7qdowpBBYBZIjwakoF2S wBkThtLIOlhgvfmtOC1DD5Rju+nVGVH4L1mthI3Be0mI+KLHbmdvsnchaKa0RhnGudm/ 6rCg== X-Gm-Message-State: AKS2vOygG8ftIIWv8NPPsyngALusHNIV0vIFoUu5gQowPLbw+E0Vgdne aAsRJyo8x+IWLfqA X-Received: by 10.98.150.157 with SMTP id s29mr20780155pfk.172.1498473919014; Mon, 26 Jun 2017 03:45:19 -0700 (PDT) Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id e189sm21280130pfe.100.2017.06.26.03.45.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2017 03:45:18 -0700 (PDT) Date: Mon, 26 Jun 2017 19:45:13 +0900 Message-Id: <87fuen58p2.fsf@calancha-pc> From: Tino Calancha To: bug-gnu-emacs@gnu.org Subject: 26.0.50; dired-do-shell-command just checks the first wildcard X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) Severity: minor Tags: patch emacs -Q: ;; Evaluate following form. (let ((foo (make-temp-file "foo" 'dir)) (bar (make-temp-file "bar" 'dir))) (dired foo) (dired-up-directory) (revert-buffer) (dired-do-shell-command (format "cp -r ? %s/?" bar) nil (dired-get-marked-files t nil))) ;; Should ask confirmation because "/?". If we change the last line to: (format "cp -r ./? %s/?" bar) nil (dired-get-marked-files t nil))) then it asks confirmation because "./?". --8<-----------------------------cut here---------------start------------->8--- commit dd809606eefea96a034eb4fe8da237003321ffd3 Author: Tino Calancha Date: Mon Jun 26 19:16:57 2017 +0900 Ask confirmation for all suspicious wildcards * lisp/dired-aux.el (dired-do-shell-command): Check that all the wildcards are right. Otherwise, ask fo confirmation (Bug#27496). diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 121bebeb65..f257a454f9 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -704,31 +704,41 @@ dired-do-shell-command (dired-read-shell-command "! on %s: " current-prefix-arg files) current-prefix-arg files))) - (let* ((on-each (not (string-match-p dired-star-subst-regexp command))) - (no-subst (not (string-match-p dired-quark-subst-regexp command))) - (star (string-match-p "\\*" command)) - (qmark (string-match-p "\\?" command)) - ;; Get confirmation for wildcards that may have been meant - ;; to control substitution of a file name or the file name list. - (ok (cond ((not (or on-each no-subst)) - (error "You can not combine `*' and `?' substitution marks")) - ((and star on-each) - (y-or-n-p (format-message - "Confirm--do you mean to use `*' as a wildcard? "))) - ((and qmark no-subst) - (y-or-n-p (format-message - "Confirm--do you mean to use `?' as a wildcard? "))) - (t)))) - (when ok - (if on-each - (dired-bunch-files (- 10000 (length command)) - (lambda (&rest files) - (dired-run-shell-command - (dired-shell-stuff-it command files t arg))) - nil file-list) - ;; execute the shell command - (dired-run-shell-command - (dired-shell-stuff-it command file-list nil arg)))))) + (cl-flet ((need-confirm-p + (cmd str) + (let ((res cmd) + (str (regexp-quote str)) + (regexp (if (string= str "?") + dired-quark-subst-regexp + dired-star-subst-regexp))) + ;; Drop all ? and * surrounded by spaces. + (while (and (string-match-p str res) + (string-match regexp res)) + (setq res (replace-match "" t t res 0))) + (string-match-p str res)))) + (let* ((on-each (not (string-match-p dired-star-subst-regexp command))) + (no-subst (not (string-match-p dired-quark-subst-regexp command))) + ;; Get confirmation for wildcards that may have been meant + ;; to control substitution of a file name or the file name list. + (ok (cond ((not (or on-each no-subst)) + (error "You can not combine `*' and `?' substitution marks")) + ((need-confirm-p command "*") + (y-or-n-p (format-message + "Confirm--do you mean to use `*' as a wildcard? "))) + ((need-confirm-p command "?") + (y-or-n-p (format-message + "Confirm--do you mean to use `?' as a wildcard? "))) + (t)))) + (when ok + (if on-each + (dired-bunch-files (- 10000 (length command)) + (lambda (&rest files) + (dired-run-shell-command + (dired-shell-stuff-it command files t arg))) + nil file-list) + ;; execute the shell command + (dired-run-shell-command + (dired-shell-stuff-it command file-list nil arg))))))) ;; Might use {,} for bash or csh: (defvar dired-mark-prefix "" --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 9, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-06-26 built Repository revision: 1771d9b8082cf967e3f8b6a436d8766560be9e8d ------------=_1499001244-9410-1--