1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"
href="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
]>
<refentry id="xdg-mime">
<refentryinfo>
<title>xdg-mime Manual</title>
<copyright>
<year>2006</year>
</copyright>
<author>
<firstname>Kevin</firstname>
<surname>Krammer</surname>
</author>
<address><email>kevin.krammer@gmx.at</email></address>
<author>
<firstname>Jeremy</firstname>
<surname>White</surname>
</author>
<address><email>jwhite@codeweavers.com</email></address>
<releaseinfo>xdg-utils 1.0</releaseinfo>
</refentryinfo>
<refmeta>
<refentrytitle>xdg-mime</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>
<refnamediv>
<refname>xdg-mime</refname>
<refpurpose>command line tool for querying information about file type handling
and adding descriptions for new file types</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>xdg-mime</command>
<arg choice="plain">query</arg>
<group choice="req">
<arg choice="plain">filetype <replaceable>FILE</replaceable></arg>
<arg choice="plain">default <replaceable>mimetype</replaceable></arg>
</group>
</cmdsynopsis>
<cmdsynopsis>
<command>xdg-mime</command>
<arg choice="plain">default</arg>
<arg choice="plain"><replaceable>application</replaceable></arg>
<arg choice="plain"><replaceable>mimetype(s)</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>xdg-mime</command>
<arg choice="plain">install</arg>
<arg><option>--mode <replaceable>mode</replaceable></option></arg>
<arg><option>--novendor</option></arg>
<arg choice="plain"><replaceable>mimetypes-file</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>xdg-mime</command>
<arg choice="plain">uninstall</arg>
<arg><option>--mode <replaceable>mode</replaceable></option></arg>
<arg choice="plain"><replaceable>mimetypes-file</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>xdg-mime</command>
<group choice="req">
<arg choice="plain"><option>--help</option></arg>
<arg choice="plain"><option>--manual</option></arg>
<arg choice="plain"><option>--version</option></arg>
</group>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1 id="description">
<title>Description</title>
<para>
The xdg-mime program can be used to query information about file types
and to add descriptions for new file types.
</para>
</refsect1>
<refsect1 id="commands">
<title>Commands</title>
<variablelist>
<varlistentry>
<term>query file</term>
<listitem>
<simpara>
Returns the file type of <replaceable>FILE</replaceable> in the form of a MIME type.
</simpara>
<simpara>
Please note that <replaceable>FILE</replaceable> names starting with a <code>-</code> will be rejected, this can be mitigated:
</simpara>
<itemizedlist>
<listitem><para>Pass absolute paths, i.e. by using <command>realpath</command> as a preprocessor.</para></listitem>
<listitem><para>Prefix known relative filepaths with a <quote>./</quote>. For example using <code>sed -E 's|^[^/]|./\0|'</code> as a preprocessor.</para></listitem>
</itemizedlist>
<simpara>
The <emphasis>query file</emphasis> option is for use inside a desktop session only.
It is not recommended to use xdg-mime query file as root.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>query default</term>
<listitem>
<simpara>
Returns the default application that the desktop environment uses for opening
files of type <replaceable>mimetype</replaceable>. The default application is
identified by its *.desktop file.
</simpara>
<simpara>
The value returned by this command may or may not match the application launched by <command>xdg-open</command> as <command>xdg-open</command> hands over to desktop specific openers most of the time which may implement their own logic.
</simpara>
<simpara>
The <emphasis>query default</emphasis> option is for use inside a desktop session only.
It is not recommended to use xdg-mime query default as root.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>default</term>
<listitem>
<simpara>
Ask the desktop environment to make <replaceable>application</replaceable>
the default application for opening
files of type <replaceable>mimetype</replaceable>. An
application can be made the default for several file types by
specifying multiple mimetypes.
</simpara>
<simpara>
<replaceable>application</replaceable> is the desktop file
id of the application and has the form vendor-name.desktop.
<replaceable>application</replaceable> must already be installed
in the desktop menu before it can be made the default handler.
The application's desktop file must list support for all the
MIME types that it wishes to be the default handler for.
</simpara>
<simpara>
Requests to make an application a default handler may be
subject to system policy or approval by the end-user. xdg-mime
query can be used to verify whether an application is the
actual default handler for a specific file type.
</simpara>
<simpara>
<emphasis>Security Note:</emphasis> Never set a handler that will blindly execute code or commands from the file being handled. Such behaviour will sooner than later lead to unintended code execution i.e. through a curious user trying to inspect a freshly downloaded file but running it by accident.
</simpara>
<simpara>
Keeping opening and executing separate actions helps with people protecting themselves from malware, the default handler is an opener, not a runner.
</simpara>
<simpara>
The <emphasis>default</emphasis> option is for use inside a desktop session only.
It is not recommended to use xdg-mime default as root.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>install</term>
<listitem>
<simpara>
Adds the file type descriptions provided in <replaceable>mimetypes-file</replaceable>
to the desktop environment. <replaceable>mimetypes-file</replaceable>
must be a XML file that follows the freedesktop.org
Shared MIME-info Database specification
and that has a mime-info element as its document root. For
each new file type one or more icons with name
<replaceable>type</replaceable>-<replaceable>subtype</replaceable>
must be installed with the <command>xdg-icon-resource</command>
command in the <emphasis>mimetypes</emphasis> context. For example the
filetype application/vnd.oasis.opendocument.text requires an
icon named application-vnd.oasis.opendocument.text
to be installed (unless the file type recommends another icon name).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>uninstall</term>
<listitem>
<simpara>
Removes the file type descriptions provided in <replaceable>mimetypes-file</replaceable>
and previously added with <command>xdg-mime install</command> from the
desktop environment. <replaceable>mimetypes-file</replaceable>
must be a XML file that follows the freedesktop.org
Shared MIME-info Database specification
and that has a mime-info element as its document root.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id="options">
<title>Options</title>
<variablelist>
<varlistentry>
<term><option>--mode</option> <replaceable>mode</replaceable></term>
<listitem>
<simpara><replaceable>mode</replaceable> can be
<emphasis>user</emphasis> or <emphasis>system</emphasis>.
In user mode the file is (un)installed for the current user
only. In system mode the file is (un)installed for all users
on the system. Usually only root is allowed to install in
system mode.
</simpara>
<simpara>
The default is to use system mode when called by root
and to use user mode when called by a non-root user.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--novendor</option></term>
<listitem>
<simpara>
Normally, xdg-mime checks to ensure that the
<replaceable>mimetypes-file</replaceable> to be installed
has a proper vendor prefix. This option can be
used to disable that check.
</simpara>
<simpara>
A vendor prefix consists of alpha characters ([a-zA-Z]) and is
terminated with a dash ("-").
Companies and organizations are encouraged to use a word
or phrase, preferably the organizations name, for which they hold
a trademark as their vendor prefix.
The purpose of the vendor prefix is to prevent name conflicts.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--help</option></term>
<listitem>
<simpara>
Show command synopsis.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--manual</option></term>
<listitem>
<simpara>
Show this manual page.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--version</option></term>
<listitem>
<simpara>
Show the xdg-utils version information.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id="env_vars">
<title>Environment Variables</title>
<para>
xdg-mime honours the following environment variables:
</para>
<variablelist>
<varlistentry>
<term>XDG_UTILS_DEBUG_LEVEL</term>
<listitem>
<simpara>
Setting this environment variable to a non-zero numerical value
makes xdg-mime do more verbose reporting on stderr.
Setting a higher value increases the verbosity.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>XDG_UTILS_INSTALL_MODE</term>
<listitem>
<simpara>
This environment variable can be used by the user or
administrator to override the installation mode.
Valid values are <emphasis>user</emphasis> and
<emphasis>system</emphasis>.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id="exitcodes">
<title>Exit Codes</title>
<para>
An exit code of 0 indicates success while a non-zero exit code
indicates failure. The following failure codes can be returned:
</para>
<variablelist>
<varlistentry>
<term><option>1</option></term>
<listitem>
<simpara>
Error in command line syntax.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>2</option></term>
<listitem>
<simpara>
One of the files passed on the command line did not exist.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>3</option></term>
<listitem>
<simpara>
A required tool could not be found.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>4</option></term>
<listitem>
<simpara>
The action failed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><option>5</option></term>
<listitem>
<simpara>
No permission to read one of the files passed on the command
line.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id="seealso">
<title>See Also</title>
<para><citerefentry><refentrytitle>xdg-icon-resource</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>,
<citerefentry><refentrytitle>xdg-desktop-menu</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>,
<ulink url="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/">Shared MIME database specification</ulink>,
<ulink url="http://www.freedesktop.org/wiki/Specifications/mime-apps-spec/">MIME applications associations specification</ulink>
</para>
</refsect1>
<refsect1 id="examples">
<title>Examples</title>
<para>
<programlisting>
xdg-mime query filetype /tmp/foobar.png
</programlisting>Prints the MIME type of the file /tmp/foobar.png, in this
case image/png
</para>
<para>
<programlisting>
xdg-mime query default image/png
</programlisting>Prints the .desktop filename of the application which is
registered to open PNG files.
</para>
<para>
<programlisting>
xdg-mime install shinythings-shiny.xml
</programlisting>Adds a file type description for "shiny"-files.
"shinythings-" is used as the vendor prefix.
The file type description could look as follows.
<programlisting>
shinythings-shiny.xml:
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-shiny">
<comment>Shiny new file type</comment>
<glob pattern="*.shiny"/>
<glob pattern="*.shi"/>
</mime-type>
</mime-info>
</programlisting>An icon for this new file type must also be installed, for
example with:
<programlisting>
xdg-icon-resource install --context mimetypes --size 64 shiny-file-icon.png text-x-shiny
</programlisting>
</para>
</refsect1>
</refentry>
|