-
Notifications
You must be signed in to change notification settings - Fork 329
Mailcap
lf
works very well with Mailcap as a launcher and a previewer.
It is an attractive option once you realize it is already installed on most systems (mailcap is part of the mime-support
package, which is a pretty common dependency).
The mailcap file allows to define for each MIME types a default action. Example:
video/*; mpv '%s';
audio/*; mpv '%s';
text/*; vim '%s'; needsterminal;
The default action is invoked with run-mailcap file.txt
.
We can also define alternate actions like the print action. The print action is invoked with run-mailcap --action=print file.txt
or by the default wrapper print file.txt
.
In the following example we add print actions to our mailcap file with the intent to use print as a lf previewer.
video/*; mpv '%s'; print=mpv --aid=no --vid=no --sid=no '%s' || : ;
audio/*; mpv '%s'; print=mpv --aid=no --vid=no --sid=no '%s' || : ;
text/*; vim '%s'; needsterminal; print=less '%s';
In order to use mailcap as a launcher we just need to set the following environment variable:
OPENER=run-mailcap
And in order to use mailcap as a previewer we just need to set the following lf option:
set previewer print
The default way to open a file using mailcap is using the run-mailcap
tool. It comes preinstalled on OpenBSD and is available as an AUR package. The latest version appears to be unable to cope with path containing spaces.
To circumvent this issue an alternative implementation can be used. The run-mailcap-rs
is a recent Rust rewrite of run-mailcap
and can handle paths with spaces without problems.