Shell Command Guessing
Based upon the name of a file, Dired tries to guess what shell command you might want to apply to it. For example, if you have point on a file named foo.tar and you press !, Dired will guess that you want to run tar xvf, and suggest that as the default shell command. You can type M-n to get the default into the minibuffer for editing. If there are several commands for a given file, type M-n several times to see each matching command in order. Dired only tries to guess a command for a single file, never for a list of marked files. @defvar dired-guess-shell-alist-default This variable specifies the predefined rules for guessing shell commands suitable for certain files. Set this to nil to turn guessing off. The elements of dired-guess-shell-alist-user (defined by the user) will override these rules. @end defvar @defvar dired-guess-shell-alist-optional This variable is like dired-guess-shell-alist-default but contains external viewers and players for various media formats. Setting this to nil turns guessing off. The variables dired-guess-shell-alist-user and dired-guess-shell-alist-default will override these rules. @end defvar @defvar dired-guess-shell-alist-user If non-nil, this variable specifies the user-defined alist of file regexps and their suggested commands. These rules take precedence over the predefined rules in the variables dired-guess-shell-alist-default and dired-guess-shell-alist-optional when dired-do-shell-command is run). The default is nil. Each element of the alist looks like
(@var{regexp} @var{command}@dots{})
@noindent where each command can either be a string or a Lisp expression that evaluates to a string. If several commands are given, all of them will temporarily be pushed onto the history. A * in the shell command stands for the file name that matched regexp. When Emacs invokes the command, it replaces each instance of * with the matched file name. To add rules for .foo and .bar file extensions, add this to your Init file:
(setq dired-guess-shell-alist-user
(list
(list "\\.foo$" "@var{foo-command}") ; fixed rule
;; possibly more rules...
(list "\\.bar$" ; rule with condition test
'(if @var{condition}
"@var{bar-command-1}"
"@var{bar-command-2}"))))
@noindent This will override any predefined rules for the same extensions. @end defvar You can find more user options with M-x customize-group =RET dired-guess RET=.