Emacs open-with dialog for opening files in mime-type fitting application.
This package uses xdg mime type information (which works only on
freedesktops like those on GNU/linux) to present an open-with
menu for
opening files in an external application as a separate process. Additionally
it provides some handy tools to associate applications with mime-types.
Until this package is available on MELPA, this package can be installed by
downloading the mediator.el
file and loading with adding
(load-file "<download-directory>/mediator.el")
to your init file.
You can also install it using straight:
(use-package mediator
:straight '(mediator
:type git
:host github
:repo "dalanicolai/mediator")
)
or you could use a Quelpa recipe.
On Spacemacs you can install the package by adding the following to your list of additional packages:
(mediator :location (recipe
:fetcher github
:repo "dalanicolai/mediator"))
Additionally you may be be interested in installing embark and/or ivy and all-the-icons-ivy-rich (see Complementary packages).
From a file-visiting buffer invoke M-x mediator-open-with
. Select the desired
application to open the file with. The command prints the chosen application and
the command used to launch the application.
Comment
- To retrieve the shell command to launch the application, the package simply uses
the first ‘word’ in its desktop-icon’s `Exec` field. If the app does not launch then, in the message buffer, check the command that was used to launch it.
- If the XDG_DATA_DIRS environment variable is not defined on your system then
either set it using
setenv
or set themediator-data-directories
variable directly in your init file.
If your desired application is not in the list, then add the file its mime-type
to the MimeType
field in its desktop file. Use M-x mediator-get-mime-type
to
print the file its mime-type. Then use M-x mediator-get-desktop-file
to
quickly navigate to the desktop (if you don’t know where the desktop file is
located then you could first use the locate
command, in Emacs or otherwise in
the terminal to locate the file). To insert the mime type run
mediator-get-mime-type
with a prefix argument C-u M-x mediator-get-mime-type
(if the buffer is read only then use mediator-sudo-edit
to sudo edit the
file). Finally, after saving the file, M-x mediato-update-mime-database
and
type your sudo password to update the desktop database(s).
See the next section for extended features using complementary packages.
Spacemacs users might like to define a keybinding in the user-config section of their init file, for example:
(spacemacs/set-leader-keys "fo" 'mediator-open-with)
The Embark
package allows for executing actions on various objects (e.g. on
filenames). You can add the mediator-open-file
action to the embark keymap by
adding the following lines to your init file:
(with-eval-after-load 'embark
(define-key embark-file-map "o" 'mediator-open-file))
If you are using Ivy, then you can add the mediator-open-file
command as
an ivy action (e.g. under m
) as follows:
(ivy-add-actions
t
'(("m" mediator-open-file "mediator-open")))
This package support icons with all-the-icons-ivy-rich. It is important
that this package gets loaded before all-the-icons-ivy-rich-mode
gets
activated (or otherwise, re-activate it).
You use all-the-icons-ivy-rich
then you can set icons for application
by adding definitions to all-the-icons-app-icon-alist
.
This package should work with all completion frameworks, but it does not add support for icons. PR’s are welcome!
Any feedback, suggestions, PR’s are welcome…