1

I have a bunch of files in the form of xyz-timestamp.log, which I want to associate with a different application, than normal log files.

I read up on mime types and found out, that I can add a mime-info file to .local/share/mime/packages describing my new mime type.

The file I came up with looks like this:

<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="text/x-xyz-log">
        <comment>XYZ Log</comment>
        <glob pattern="xyz*.log" weight="100" />
    </mime-type>
</mime-info>

But it doesn't catch. It seems like only *.log patterns or specific files like sources.list for apt work and not one, where the asterisk is in the middle.

The free desktop standard mentions nothing about not supporting certain glob features or what have you, so I'm completely in the dark on this.

UPDATE:

I finally got it working by using the <magic> element. It alone was not enough seemingly, because I was still beaten out by the glob of normal log files, even after declaring, that this is a subtype of it. Only the combination of a glob of my own AND the magic made it work.

<?xml version="1.0"?>                                                           
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">       
    <mime-type type="application/x-xyz-log">                                 
        <comment>XYZ Log</comment>                                           
        <sub-class-of type="text/x-log" />                                                               
        <glob pattern="*.log" />                                                                                  
        <magic priority="100">                                                  
            <match type="string" offset="0:256" value="XYZ-Service started. LOLJK" />
        </magic>                                                                
    </mime-type>                                                                
</mime-info>   

1 Answer 1

1

The glob pattern seems to have been dumbed down intentionally; the section about that element states:

KDE's glob system replaces GNOME's and ROX's ext/regex fields, since it is trivial to detect a pattern in the form '*.ext' and store it in an extension hash table internally. The full power of regular expressions was not being used by either desktop, and glob patterns are more suitable for filename matching anyway.

5
  • I saw that, but searching for KDE glob doesn't bring up anything. So KDE's glob system just sucks, is that what that paragraph is supposed to tell me? :(
    – Minix
    Nov 23, 2021 at 12:54
  • That's how I read it: KDE just does "*.ext" patterns (trivial pattern) and the full extended regular expression (ext/regex) could probably have done more. Had they just waited and asked us! ;-)
    – flowtron
    Nov 23, 2021 at 13:19
  • I've been grepping through the other mime xml files and have only seen xyz.* and xyz* glob patterns. Trying out a few with empty files, I can't get them to be recognized. So either there is something else (no magic tags in those files) or the package maintainers haven't noticed yet, that their mime files don't work anymore.
    – Minix
    Nov 23, 2021 at 13:26
  • They work for me: touch foo,v && mimetype foo,v and touch SConscript.test-me && mimetype SConscript.test-me both show these patterns work as well as the most iconic of patterns "*.ext"; but the pattern "[0-9][0-9][0-9].vdr" does not work for me, it is recognized as text/plain, but the same empty file is said to be video/mpeg if I rename it to 123.vob
    – flowtron
    Nov 23, 2021 at 13:45
  • I always just look what the file manager tells me, but maybe there are some slight differences. I'll just try to go by magic I guess.
    – Minix
    Nov 23, 2021 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .