Description: | Open files by MIME-type or file name using regular expressions. |
Latest Version: | 2023 |
Source Code: | src/ |
Architecture: |
|
Dependencies: |
|
Build Dependencies: |
|
Optional Dependencies: |
|
Arch Repositories: |
|
AUR Page: | mimeo |
Arch Forum Thread: | 86855 |
Tags: |
Mimeo uses MIME-type file associations to determine which application should be used to open a file. It can launch files or print information such as the command that it would use, the detected MIME-type, etc. It is also possible to use regular expressions to associate arguments with applications. The most common example is to open URLs in browsers or associate file extensions with applications irrespective of their MIME-type.
Mimeo tries to adhere to the relevant standards on freedesktop.org and should therefore be compatible with other applications that set or read MIME-type associations, e.g. PCManFM.
Please notify the author of any non-standard behavior so that it can be corrected.
See mimeo --help
for options and usage information.
To open some files foo, bar and /somewhere/else/baz just run
mimeo foo bar baz /somewhere/else/baz
To suppress output on the terminal in which mimeo is run, use the
-q
option.
Mimeo is able to update MIME-type associations (add, remove, clear) and configure defaults. It can also update MIME-cache files and check for invalid desktop entries. See “mimeo –help” for more information.
test
is an extensionless Bash script.
# find Leafpad's desktop file
> mimeo --app2desk leafpad
leafpad
leafpad.desktop
# determine "test" file's MIME-type
> mimeo -m test
test
application/x-shellscript
# associate "application/x-shellscript" with Leafpad
> mimeo --add application/x-shellscript leafpad.desktop
> mimeo --app2desk medit
medit
medit.desktop
> mimeo --add 'glob:text/*' medit.desktop
These are just a few quick examples of how to create associations using the associations file. See “mimeo –assoc-help” for more information.
Open YouTube videos in VLC:
vlc --one-instance --playlist-enqueue %U
^https?://(www.)?youtube.com/watch\?.*v=
Open HTTP(S) URLs with Firefox:
/usr/bin/firefox %U
^https?://
Note that the order of matching in the file is important and that the YouTube video URL matcher must come before the general HTTP(S) one, otherwise YouTube links would be opened in Firefox.
Recognize Perl (.pl), Python (.py), Haskell (.hs) files by extension and open them with medit.
/usr/bin/medit %F
\.p[ly]%
\.hs%
Open various media files in VLC by extension:
/usr/bin/vlc --one-instance --playlist-enqueue %F
\.mp3$
\.flac$
\.avi$
\.mpg$
\.flv$
$ mimeo --help
usage: Mimeo [options] [<arg> ...]
Open files using MIME-type and custom user associations.
positional arguments:
<arg>
options:
-h, --help show this help message and exit
Query Operations:
Operations to obtain information.
--assoc-help Display information about the custom associations
file.
--mimeman-help Display information about managing MIME-type
associations.
--filepath-help Display information about configuration and data
filepaths.
-c, --command Print the full command(s) and exit.
-d, --desktop Print the associated desktop file names and paths and
exit.
-m, --mimetype Print the detected MIME-type(s) for the given
arguments and exit. The arguments may be paths, Mimeo
MIME-type matchers, or URIs. If no arguments are
given, print all known MIME-types.
--finddesk Return the paths to the given desktops if they exist.
--mime2desk List desktop files associated with the given MIME-
types.
--app2desk List desktop files that use the given executables and
exit. If no arguments are given then the executables
of every desktop file will be listed.
--app2mime List MIME-types that the given executables are
associated with in their desktop files and exit. If no
application is given, all applications will be listed.
--desk2field <desktop entry field>
List the values of a desktop entry field per desktop,
e.g. "Exec" or "MimeType".
--mimeapps-list Print the paths to detected mimeapps.list files.
Modification Operations:
Operations to change associations and preferences. If no MIME-type matcher
is given then the MIME-types in the desktop files will be used.
--update Update associations and cache files.
--add <MIME-type matcher | filepath | desktop file> [<desktop file> ...]
Associate MIME-types with desktop files. See "--
mimeman-help" for more information.
--unadd <MIME-type matcher | filepath | desktop file> [<desktop file> ...]
Undo an --add operation.
--remove <MIME-type matcher | filepath | desktop file> [<desktop file> ...]
Remove associations by adding them to the "Removed
Associations" section of mimeapps.list. This can
effectively hide system-associations from the user.
This does not affect default. Use "--clear" to forget
a user-association. See "--mimeman-help" for more
information.
--unremove <MIME-type matcher | filepath | desktop file> [<desktop file> ...]
Undo a --remove operation.
--prefer <MIME-type matcher | filepath | desktop file> [<desktop file> ...]
Set a default association. See "--mimeman-help" for
more information.
--unprefer <MIME-type matcher | filepath | desktop file> [<desktop file> ...]
Undo a --prefer operation.
--clear <MIME-type matcher | filepath | desktop file> [<desktop file> ...]
Clear associations. If no desktop files are specified,
all associations for the MIME-type(s) will be cleared.
To clear all associations for a desktop file, use "--
clear 'glob:*' <desktop file>". This affects defaults.
See "--mimeman-help" for more information.
--create <filename> <Name> <Exec> <MIME-type matcher or ""> <"term" or "noterm">
Create a minimal desktop file. Edit the created file
if necessary. If an empty string is passed instead of
a MIME-type matcher, the file will not specify any
MIME-type associations. The fifth argument indicates
if "Terminal" should be set to "true" in the created
file. See "--mimeman-help" for more information. The
created files are saved in $XDG_DATA_HOME/applications
(~/.local/share/applications by default).
Configuration:
Various configuration options.
-a <filepath>, --assoc <filepath>
Specify a file that associates regular expressions
with custom commands. This can be used for opening
URLs, for example. See "--assoc-help" for details. See
--filepath-help for default paths.
--no-assoc Do not use the default associations file.
--no-def-args Omit the default arguments.
--user Restrict operations to user files.
--system Restrict operations to system files. This is mostly
useful for updating system desktop files and MIME
information as root.
-q, --quiet Suppress all output from launched applications.
--term <cmd> Terminal command to use when launching applications
with desktop files that specify "Terminal=true". It
will be split into words using shlex.split. A word
equal to "%s" will be replaced by the separate words
of the application command. A word equal to "'%s'"
will be replaced by a single word containing the
joined words of the application command. Any other
instance of "%s" within a word will be replaced by the
joined words of the application command. If "%s" does
not appear within the terminal command then the
separate words of the application command will be
appended to the end of the command. Examples: "urxvt
-e", "urxvt -e %s", "xterm -e bash -c '%s'". A literal
"%" may be escaped with "%%". Use the default
arguments file or a shell alias to automatically pass
this argument.
--exec Run the Exec fields from the given desktop files.
--cmd-prefix <cmd> [<arg> ...]
Prefix commands and arguments to the desktop commands.
For example, this can be used to run commands with
sudo, gksudo, etc. while still running $(prog) as a
regular user.
--by-content-only Determine MIME-type of files from the content only.
--by-content-first Check file content before name when determining MIME-
type.
--by-name-only Determine MIME-type of files from the name only.
--no-follow Do not follow symlinks.
--deprecated Use deprecated directories. See --filepath-help for
details.
--current-desktop Modify associations of the current desktop as
specified in $XDG_CURRENT_DESKTOP. Ignored if
$XDG_CURRENT_DESKTOP is not set.
--debug Enable debugging messages.
--full-path Return full paths to desktop files for some outputs..
--show-all For some output, show all possibilities rather than
just the first. This can be used with --command for
example.
--swap Swap the way displayed information is organized, e.g.
display input arguments per MIME-type instead of MIME-
types per input argument with --mimetype. This does
not work for all query operations.
If no operation is specified, the commands determined by "--command" will be
run, i.e. the passed arguments will be opened. See --filepath-help for further
configuration options such as passing default arguments.
$ mimeo --assoc-help
USAGE
The associations file contains commands followed by regular expressions, all
on separate lines. It enables the user to associate arbitrary strings with
applications. This relies only on the argument string itself and is
independent of any associated file or MIME-type.
Association files can be specified on the command line. Mimeo will also
check for association files in default locations. Check the main help message
for details.
COMMANDS
The command is parsed as a .desktop "Exec" field and may thus contain
variables such as "%f" and "%F". In the absence of such, the input argument is
passed as the final argument to the command.
See the .desktop documentation for rules about quoting etc.:
http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables
REGULAR EXPRESSIONS
The regular expressions are indented by exactly two spaces (" ") and are
associated with the previous command. Any argument that matches a regular
expression will be opened with its associated command.
The two-space indentation allows the use of regular expressions that begin
with whitespace.
OTHER
The file may contain empty lines and comments. The first character of a
comment line must be "#".
EXAMPLES
Associate HTTP and HTTPS URIs with Firefox:
/usr/bin/firefox %U
^https?://
Associate Perl (*.pl), Python (*.py) and text (*.txt) files with gVim:
/usr/bin/gvim %F
\.p[ly]$
\.txt$
Enqueue various media files in a running instance of VLC:
/usr/bin/vlc --one-instance --playlist-enqueue %F
\.mp3$
\.flac$
\.avi$
\.mpg$
\.flv$
$ mimeo --mimeman-help
MIME-manager Help
<MIME-type matcher>
MIME-types may be specified in one of three ways using different
"MIME-type matchers":
Direct Match
The matcher is interpretted as a MIME-type string, e.g. "text/x-python".
Shell-style Globbing
If the matcher begins with "glob:" then the rest of it will be
interpretted as a shell-style globbing pattern and it will be matched
against all known MIME-types.
For example, "glob:text/x-*" would be expanded to all known
MIME-types beginning with "text/x-".
Regular Expressions
If the matcher begins "regex:" then the rest of it will be
interpretted as a (Perl-style) regular expression and it will be matched
against all known MIME-types.
For example, "regex:^text/x-.*" would be equivalent to
"glob:text/x-*"
<desktop.file>
The name of a desktop file, with the ".desktop" extension. Desktop files
are found in the "applications" sub-directory of directories in
$XDG_DATA_HOME and $XDG_DATA_DIRS
<Name>
The value of the "Name" key in a desktop file.
<Exec>
The value of the "Exec" key in a desktop file.
See
http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables
for details.
EXAMPLES
Set firefox as the prefered browser for all associated MIME-types:
mimeo --prefer firefox.desktop
To set multiple preferences, pass the option multiple times:
mimeo --prefer firefox.desktop --prefer vlc.desktop
If both desktop arguments are passed together then their MIME-types will be
pooled and both will be set as preferred applications for the pool, which is
unlikely to be what you want:
# Don't do this. Use the previous command instead.
mimeo --prefer firefox.desktop vlc.desktop
This is a consequence of the way the command is parsed. It is usually used
with a MIME-type matcher. For example, to set vlc and mplayer as preferred
applications for videos, with vlc taking precedence, you could use:
mimeo --prefer 'glob:video/*' vlc.desktop mplayer.desktop
To check which MIME-types will be matched, use:
mimeo --mimetype 'glob:video/*'
It is possible to create custom desktop files for your own commnds. For
example, to create one for Feh and associate all images with it:
mimeo --create feh.desktop Feh 'feh %F -F -Z' 'glob:image/*' "noterm"
Now set feh.desktop as the default for PNG and JPEG images:
mimeo --prefer 'regex:^image/(png|jpe?g)$' feh.desktop
Instead of passing <MIME-type matcher>, the MIME-type can be parsed from a
file path. For example, to prefer feh.desktop for all PNG images, use:
mimeo --prefer /path/to/foo.png feh.desktop
--exec
option to run commands from desktop file
arguments.--create
command to “noterm”
for non-terminal applications instead of an empty string.--desk2field
when omitting “.desktop” extensions.--show-all
option to print multiple commands for
each argument.--show-all
.--fullpath
to --full-path
.--field2desk
. Use --desk2field
with --swap
instead.--filepath-help
.modify_associations
.--desk2field
, --field2desk
,
--fullpath
).--finddesk
option to query paths to desktop
files.--desk2mime
and --mime2desk
.Mimeo.py
for details]. The latest
version has deprecated $XDG_DATA_DIR/applications
(~/.local/share/applications
) and all files in it. Use the
--deprecated
flag to continue to use these, including
custom desktop files created by Mimeo.--purge
option.foo.desktop /path/to/foo.desktop
now
only contain /path/to/foo.desktop
.defaults.list
to
mimeapps.list
when updating
mimeapps.list
.Mimeo subsumed Mimeman’s functionality, with needed corrections. Mimeman was a dirty kludge created without any knowledge of the standard. Mimeo is now able to manage MIME-type associations and create desktop files.
Mimeo’s algorithm for determing associations has also been corrected in several places.