Mailcap - gokcehan/lf GitHub Wiki
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).
Mailcap file
The mailcap file (~/.mailcap) allows defining a default action for each MIME types:
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';
lf integration
In order to use mailcap as a launcher we 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
Troubleshooting
run-mailcaphangs when opening paths that contain spaces.- Check whether
tempfileutility is present on your system. It is provided by thedebianutilspackage.
- Check whether
Alternative launchers
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.
It depends on the debianutils package which can be cumbersome to install on some non-Debian systems.
Luckily, there are alternatives.
run-mailcap-rs
The run-mailcap-rs is a recent Rust rewrite of run-mailcap.
It needs rust, but doesn't depend on the debianutils package.
mopen
The mopen script leverages the Python mailcap module to do the heavy lifting.
It also doesn't depend on debianutils.