Next: , Previous: , Up: Top   [Contents][Index]

4 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 you want to ‘tar xvf’ it and suggest that as the default shell command.

The default is mentioned in brackets and you can type M-n to get the default into the minibuffer and then edit it, e.g., to change ‘tar xvf’ to ‘tar tvf’. If there are several commands for a given file, e.g., ‘xtex’ and ‘dvips’ for a .dvi file, you can type M-n several times to see each of the matching commands.

Dired only tries to guess a command for a single file, never for a list of marked files.

The following variables control guessing of shell commands:

Variable: 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.

Variable: dired-guess-shell-alist-user

If non-nil, this variables specifies the user-defined alist of file regexps and their suggested commands. These rules take precedence over the predefined rules in the variable dired-guess-shell-alist-default (to which they are prepended) when dired-do-shell-command is run). The default is nil.

Each element of the alist looks like

(regexp command…)

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.

You can set this variable in your ~/.emacs. For example, to add rules for ‘.foo’ and ‘.bar’ file extensions, write

(setq dired-guess-shell-alist-user
       (list "\\.foo$" "foo-command");; fixed rule
       ;; possibly more rules...
       (list "\\.bar$";; rule with condition test
              '(if condition

This will override any predefined rules for the same extensions.

Variable: dired-guess-shell-case-fold-search

If this variable is non-nil, dired-guess-shell-alist-default and dired-guess-shell-alist-user are matched case-insensitively. The default is t.

Variable: dired-guess-shell-gnutar

If this variable is non-nil, it specifies the name of the GNU Tar executable (e.g., tar or gnutar). GNU Tar’s ‘z’ switch is used for compressed archives. If you don’t have GNU Tar, set this to nil: a pipe using zcat is then used instead. The default is nil.

Variable: dired-guess-shell-gzip-quiet

A non-nil value of this variable means that ‘-q’ is passed to gzip, possibly overriding a verbose option in the GZIP environment variable. The default is t.

Variable: dired-guess-shell-znew-switches nil

This variable specifies a string of switches passed to znew. An example is ‘-K’ which will make znew keep a .Z file when it is smaller than the .gz file. The default is nil: no additional switches are passed to znew.

Variable: dired-shell-command-history nil

This variable holds the history list for commands that read dired-shell commands.

Next: , Previous: , Up: Top   [Contents][Index]