89 points · by vermaden · 5y ago · 85 comments
$ xdg-mime query filetype file.docx
application/vnd.openxmlformats-officedocument.wordprocessingml.document
$ xdg-mime query filetype file.xls
application/vnd.ms-excelMaybe you have more recent xdg-utils version?
I run 1.1.3 here.
Maybe what's missing is the libreoffice package? It seems like all these types are provided by /usr/share/mime/packages/libreoffice.xml on my system (which is read by update-mime-types).
Arguably this is a common enough format that you shouldn't really need libreoffice installed to have it, though I would think any other office program would have it. I think /etc/mime.types serves as the ultimate fallback, though it doesn't have entries for libreoffice file extensions on my system.
The Garbage In, Garbage Out principal applies here.
For anyone interested about how the plumbing, here are the specs:
shared-mime-info-spec[0] is for mapping glob patterns, magic numbers, string fragments, etc. to MIME types; and desktop-entry-spec[1] is for defining what an application is, its icon, how to launch it, what MIME types it handles, etc.
[0] https://freedesktop.org/wiki/Specifications/shared-mime-info...
[1] https://www.freedesktop.org/wiki/Specifications/desktop-entr...
On my (Debian) system, the following packages provide the definitions that map *.docx files to the appropriate MIME type:
$ grep -l '\*.docx' /usr/share/mime/packages/*.xml | xargs dpkg -S
shared-mime-info: /usr/share/mime/packages/freedesktop.org.xml
libreoffice-common: /usr/share/mime/packages/libreoffice.xml
... and subsequently: $ xdg-mime query filetype Downloads/something.docx
application/vnd.openxmlformats-officedocument.wordprocessingml.document
$ xdg-mime query default application/vnd.openxmlformats-officedocument.wordprocessingml.document
libreoffice-writer.desktop*Storing the MIME type separately is definitely a good thing. This isn't the only way you do it. You start by checking the MIME type and then fall back to one of our crude detection mechanisms, like guessing what the file type is based on extension.
We already store plenty of metadata with files--permissions and timestamps for starters. The metadata is sometimes lost when you transfer to another system. That's OK... you can repair the metadata.
Given that this metadata is already present in the HTTP protocol, it's present in files embedded in email messages, and given that extended attributes are supported by many different filesystems, I think this solution is completely workable. You could make the argument that since we spend so much time interacting with files over HTTP, that having a MIME type in the metadata is actually the common way to do things.
Could you give an example where one would want to choose the MIME type of some data, from a selection of options?
And, if it happens that the file goes through such a system that doesn't understand mimetypes, you're only back to the status quo of having to sniff the type from hints like extension or content.
Would you say that all the common desktop filesystems, flash memory filesystems, optical filesystems, archive formats, etc. today all aren't robust since they don't do this?
> ... you're only back to the status quo of having to sniff the type from hints like extension or content.
Combining multiple methods does solve that problem, but doesn't it kind of negate the benefits too?
Also, I still think there are some issues. For example, it would need the creation of new mime type changing UI, which might be a hard thing to teach laypeople (they already barely understand extensions). And what do you do if the internal mime type disagrees with the extension? Aside from just being confusing, that could be purposely abused by malware.
The file type determine which applications could be used to open a file (by drag-and-drop onto the application, or via the application's Open dialog box).
Applications could register to open a type, I think it would default to the creator.
Of course, that wound up with things like resource forks, and that didn't really play well with anyone else's file system.
What was stored in a resource fork (of each application) was the declaration “I am [four byte creator code]; I can open these [four byte file types]. That’s the information that the Finder built its databases from (https://www.folklore.org/StoryView.py?project=Macintosh&stor...)
That easily could have been moved into the file proper (as AppleSingle (https://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_fo...) did, but another (and IMO better for this purpose) option would have been to move that info into a special code segment in the data fork (in Unix parlor; old-style Mac OS programs stored their code in code segments in the resource fork)
Also, I think Mac OS still uses https://en.wikipedia.org/wiki/Uniform_Type_Identifier, which are an improvement over file types and creator codes (you can, for example, express the fact that every html file is a text file with it)
Never had much luck with xdg-open
Will definitely dig into it to either use it directly or at least try to implement it in mine see.sh.
Also IMHO you should add short 'youtu.be' regex handler :)
Regards.
pdftotext seems reasonable and looks to be part of the Debian lessfilter.
#!/bin/sh
echo -n "$1" | xclip -selection primary; notify-send "URL Copied" "$1"It is for this reason that `echo` is generally frowned upon for programmatic input, and `printf %s "$1"` is recommended; as this is guaranteed to not interpret, and copy dash-leading strings to the output verbātim.
Modern shells also typically have `echo` as a builtin and can have quite different behavior.
https://stackoverflow.com/questions/33784892/bash-vs-dash-be...
Any topics You would like to be covered?
it shows a dialog with all the associated application to the user to choose from
~/.local/share/applications/mimeapps.list
~/.config/mimeapps.list
In here you find the MIME type pointing at a .desktop file (app launcher), it's a matter of changing that. Mine for example related to using Firefox: [Default Applications]
x-scheme-handler/http=firefox.desktop
x-scheme-handler/https=firefox.desktop
Find the .desktop file you want to launch and just update that bad boy. Most DEs have a GUI tool to manage this for you without having to resort to manual editing...[0] https://www.freedesktop.org/wiki/Specifications/desktop-entr...
On my (Debian) system, firefox and chromium ship their .desktop files.
I use BROWSER environment variable for that.
It seems to even override XDG settings.
% xdg-settings set default-web-browser firefox.sh.desktop
xdg-settings: $BROWSER is set and can't be changed with xdg-settings
% echo ${BROWSER}
firefox
Hope that helps.EDIT: You also got me nice idea - to add http(s):// and ftp:// support for mine see.sh opener :)