3

I want to open several types of files in Dired by different external applications.
For example:

  • .doc files with LibreOffice
  • .pdf files with evince
  • .jpg files with pinta
  • etc...

How do i configure this?

3

Use Dired-x (standard library dired-x.el: put (require 'dired-x) in your init file).

Customize option dired-guess-shell-alist-user. C-h v tells you:

dired-guess-shell-alist-user is a variable defined in dired-x.el.

Its value is nil

Documentation:

User-defined alist of rules for suggested commands.

These rules take precedence over the predefined rules in the variable dired-guess-shell-alist-default (to which they are prepended).

Each element of this list looks like

(REGEXP COMMAND...)

where each COMMAND can either be a string or a Lisp expression that evaluates to a string.

If this expression needs to consult the name of the file for which the shell commands are being requested, it can access that file name as the variable file.

If several COMMANDs are given, the first one will be the default and the rest will be added temporarily to the history and can be retrieved with M-x previous-history-element (M-p) .

The variable dired-guess-shell-case-fold-search controls whether REGEXP is matched case-sensitively.

You can customize this variable.

Then just use ! or & on files in Dired. Use M-n to retrieve the default value of the program to run, which will come from your entries in the option value.

1

Using & from dired prompts to open each file with an external application.
Searching and trying, these elisp lines made it work:

  (setq dired-guess-shell-alist-user '(("\\.pdf\\'" "evince")
                                   ("\\.doc\\'" "libreoffice")
                                   ("\\.docx\\'" "libreoffice")
                                   ("\\.ppt\\'" "libreoffice")
                                   ("\\.pptx\\'" "libreoffice")
                                   ("\\.xls\\'" "libreoffice")
                                   ("\\.xlsx\\'" "libreoffice")
                                   ("\\.jpg\\'" "pinta")
                                   ("\\.png\\'" "pinta")
                                   ("\\.java\\'" "idea")))
  • 1
    Each setq you perform this way changes the value of the variable, so I doubt this works. You can check the final value with C-h v dired-guess-shell-alist-user. – JeanPierre Aug 10 '18 at 19:15
  • @JeanPierre Yes, you are right. Newbie error. I just corrected it with some values I am currently using. Tested it using use-package. – nephewtom Sep 3 '18 at 11:32

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.