]> git.eshelyaron.com Git - emacs.git/commitdiff
Add user option for controlling dired-do-shell-command prompt
authorAllen Li <darkfeline@felesatra.moe>
Tue, 22 Mar 2022 16:48:13 +0000 (17:48 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 22 Mar 2022 16:48:13 +0000 (17:48 +0100)
* doc/emacs/dired.texi (Shell Commands in Dired): Document option
* lisp/dired-aux.el (dired-confirm-shell-command): Add option
(dired-do-shell-command): Check option before prompting
(bug#29465).

doc/emacs/dired.texi
lisp/dired-aux.el

index e18c8b048bcd111153946c6ee577defa4568cef6..27df269ce7b313145376162420de0c8f3e541175 100644 (file)
@@ -1007,6 +1007,7 @@ subdirectories whose names match @code{grep-find-ignored-directories}.
 @findex dired-do-shell-command
 @kindex ! @r{(Dired)}
 @kindex X @r{(Dired)}
+@vindex dired-confirm-shell-command
 The Dired command @kbd{!} (@code{dired-do-shell-command}) reads a
 shell command string in the minibuffer, and runs that shell command on
 one or more files.  The files that the shell command operates on are
@@ -1043,7 +1044,8 @@ list of file names, putting them into one tar file @file{foo.tar}.
 If you want to use @samp{*} as a shell wildcard with whitespace around
 it, write @samp{*""}.  In the shell, this is equivalent to @samp{*};
 but since the @samp{*} is not surrounded by whitespace, Dired does not
-treat it specially.
+treat it specially.  Emacs will prompt for confirmation if you do
+this, unless @code{dired-confirm-shell-command} is @code{nil}.
 
 @item
 Otherwise, if the command string contains @samp{?} surrounded by
index 56897826cbc4c6e92c5d58c72ab4c1d76dc785ef..956899c20511a11deeed43ace4a69cf9d7d72375 100644 (file)
@@ -795,6 +795,15 @@ offer a smarter default choice of shell command."
       (dired-mark-pop-up nil 'shell files
                         'read-shell-command prompt nil nil))))
 
+;;;###autoload
+(defcustom dired-confirm-shell-command t
+  "Whether to prompt for confirmation for ‘dired-do-shell-command’.
+If non-nil, prompt for confirmation if the command contains potentially
+dangerous characters.  If nil, never prompt for confirmation."
+  :type 'boolean
+  :group 'dired
+  :version "29.1")
+
 ;;;###autoload
 (defun dired-do-async-shell-command (command &optional arg file-list)
   "Run a shell command COMMAND on the marked files asynchronously.
@@ -873,7 +882,9 @@ can be produced by `dired-get-marked-files', for example.
 
 `dired-guess-shell-alist-default' and
 `dired-guess-shell-alist-user' are consulted when the user is
-prompted for the shell command to use interactively."
+prompted for the shell command to use interactively.
+
+Also see the `dired-confirm-shell-command' variable."
   ;; Functions dired-run-shell-command and dired-shell-stuff-it do the
   ;; actual work and can be redefined for customization.
   (interactive
@@ -891,6 +902,8 @@ prompted for the shell command to use interactively."
          (ok (cond
               ((not (or on-each no-subst))
                (error "You can not combine `*' and `?' substitution marks"))
+              ((not dired-confirm-shell-command)
+               t)
               ((setq confirmations (dired--need-confirm-positions command "*"))
                (dired--no-subst-confirm confirmations command))
               ((setq confirmations (dired--need-confirm-positions command "?"))