opn, pronounced open (creative, I know), allows you to pick the application to open a file with
in the terminal from a list of preferred applications.
- Provides a terminal interface with a list of supported applications that can open a file or a URL.
- The list of supported applications is based on the well-established
.desktopfiles. - bash/fish/zsh completions.
- Opens both GUI and terminal applications.
- Integrates with various tools such as:
- The MIME type of a file can be explicitly set using extended file attributes.
See Install.md.
To determine the list of programs that are suggested for a file, the MIME Applications Specification and Shared MIME-info specification are used.
A simplified explanation:
.desktopfiles, located in$XDG_DATA_HOME/applicationsand$XDG_DATA_DIRS/applications, specify the name of applications, their path, and optionally some MIME types they can open. These files are typically included when installing applications.
The name of these files equals the desktop ID. See the Desktop Entry spec.mimeapps.listfiles, located in one of the specified directories, associates a MIME type with desktop IDs.opnreads these desktop andmimeapps.listfiles to determine the MIME-application association.- When
opn file path/to/fileis executed,xdg-mimeorfileis used to determine the MIME type of the file. The MIME type and its subclasses are then looked up in the MIME-application index to find all associated applications.
shared-mime-infoUsed for determining the subclasses of a MIME type.xdg-mime(preferred, better accuracy,xdg-utilspackage) orfile
Some applications require a terminal to launch in. Examples of this include; vim, nano, nnn, and opn
itself. These applications have Terminal=true in their respective desktop files.
Unfortunately, there is no specification yet, though
one is being developed,
on how to set a preferred terminal emulator across Desktop Environments or systems without one.
This requires an environment variable to make opn aware of your preference.
Specify the terminal to be launched using the TERMINAL_COMMAND or OPN_TERM_CMD environment
variable. The latter takes precedence. E.g:
footgnome-terminal --
By default, GUI applications are started detached from the terminal and terminal applications are opened in the current terminal. For documentation on how to control this behavior, see docs/cli/opn_file.md#attaching-to-terminal.
Open a file/URL using opn resource /path/or/URL.
Open a file using opn file /path/to/file.
Open a URL using opn url protocol://example.com.
For detailed usage, see opn --help or view the CLI docs.
When opening a file, explicitly specifying its MIME type is possible by using the
--mime-type option. E.g.:
opn file --mime-type text/plain go.mod
opn reads the user.mime extended file attribute if supported, to determine the MIME type.
This allows a file to be permanently marked as having a specific type.
Example of setting the attribute, explicitly state that the go.mod file has the text/plain type:
setfattr -n user.mime -v text/plain go.mod
See Shared MIME info, Storing the MIME type using Extended Attributes.
- Pacman/package manager hook to update cache
- Add examples on how to change preferred applications.
- Support DBUS activation for starting applications. Pending interest.
- We could write our own implementation of
xdg-query mimebased onmime.cacheand drop thefile/xdg-utilsrequirement thoughxdg-utilsis a common dependency so it is not very likely to that dropping it will benefit the user. - Add autocomplete for opn query desktop-locations
- Add autocomplete for opn query mime