I was ready to continue reading my book. Double-clicked and BAM! The not so great epdf-viewer popped up. Not this time fellow. So like every average linux man/woman/etc I decided to change the default application for pdf files. I alread had foxit-reader installed. So I knew it was oppening it via xdg-open. The xdg-open relies on the xdg-mime to query and determine the default application for a given file type. But there is a catch. I didn't know what flags to pass. So like my professor always said: "When in doubt, man it".
man xdg-mime
And there it was. xdg-mime default application mimetype(s)
. Only one teeny tiny problem. What is the mimetype here?
Is it file extension? or what we web developers called the content-type? It's not application/pdf right?
So if the epdf-viewer is oppening it, there should be a key/val somewhre. but where?
there
> xdg-mime query default image/png
viewnior.desktop
So I have command is 100% doing some IO. So I decided to strace it.
> strace -e file xdg-mime query default image/png
...
newfstatat(AT_FDCWD, "/home/tur1ng/.config/mimeapps.list", {st_mode=S_IFREG|0644, st_size=2399, ...}, 0) = 0
...
Great. So a simple cat-greping should do the trick.
> cat ~/.config/mimeapps.list | grep pdf
application/pdf=epdfview.desktop;
Aha, I was right. To be honest the second I saw image/png I knew it was the same as the content-type. But regardless, I was right.
So let's xdg-mime it.
> xdg-mime default foxitreader.desktop application/pdf
Beautiful. I can now read my book in peace.
Turns out xdg-mime accepts another flag. Of course it does. xdg-mime query filetype filename
and it will return the mimetype.
> xdg-mime query filetype ./anything.pdf
application/pdf