From: Allen Li Date: Tue, 22 Mar 2022 16:48:13 +0000 (+0100) Subject: Add user option for controlling dired-do-shell-command prompt X-Git-Tag: emacs-29.0.90~1931^2~989 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=142478c0958a233d68616220a6ef49c13f6b28dc;p=emacs.git Add user option for controlling dired-do-shell-command prompt * 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). --- diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index e18c8b048bc..27df269ce7b 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -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 diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 56897826cbc..956899c2051 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -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 "?"))