4

I'm trying to set the default application for R noweb files but fail to find the place where this is specified. The reason for this is that my file managers seem to determine the file type by filename extension (.Rnw) rather than or in addition to the scheme specified by freedesktop.org (that is: mimeapps.list, mimeinfo.cache, defaults.list...)

I tried pcmanfm and thunar as file managers. They agree in determination of the file type but differ from the xdg-mime query filetype utility. See below for minimal example and config files.

Moreover, the xdg-mime utility seems to ignore the local mimeapps.list, yet the filemanager honours it.

The question is: Is my assumption right that file types are determined by name extension in these file managers and where do I find the associated configuration?

I use Awesome WM as window manager an pcmanfm as desktop manager.

Update: I found this tutorial on file extensions in pcmanfm, but my problem is still that mime type and inferred type by pcmanfm don't match (rnoweb.Rnw is MIME type text/plain, rnoweb0.Rnw is inode/x-empty, yet pcmanfm lists both as R Sweave file)

Update2 [SOLVED]: @mji proposed an xml file to be put in ~/.local/share/mime/packages. This file already exists as /usr/share/mime/text/x-r-sweave.Rnw. It turns out that changing the <comment> tag in that file changes the Description column in thunar and pcmanfm. It also assigns the MIME type x-r-sweave to the files. I found this already in my question, but overlooked it (I searched for x-r-noweb)


Minimal example:

I created four files in an empty directory. Two empty, two with sample content:

touch plain0 rnoweb0.Rnw

cat > plain <<EOF
text
EOF

cat > rnoweb.Rnw <<EOF
<<>>=
1+1
@
EOF

I run xdg-mime query filetype and xdg-mime query default on these files to obtain the following results:

filename      MIME type           Default app
-------------------------------------------------
plain         text/plain          medit.desktop
plain0        inode/x-empty
rnoweb0.Rnw   inode/x-empty
rnoweb.Rnw    text/plain          medit.desktop

However, thunar and pcmanfm list the type of the *.Rnw files as "R Sweave file" and the plain* files as plain text document ("Einfaches Textdokument" in German). Default application listed in the file managers is RStudio for the *.Rnw and GVim for plain*.

Plain text files are opened with GVim, disagreeing with the xdg-mime utility but in accordance to settings in my local .local/share/applications/mimeapps.list

The only files on my system matching locate mimeinfo and locate mimeapps are

/etc/xdg/mimeapps.list
/usr/share/applications/mimeinfo.cache
~/.local/share/applications/mimeapps.list
~/.local/share/applications/mimeinfo.cache

grepping for the ocurrence of rstudio (rstudio.desktop) in these files yields (similar results summarized in {...})

/usr/share/applications/mimeinfo.cache 
    application/x-r-data=rstudio.desktop;
    application/x-r-project=rstudio.desktop;
    text/css=rstudio.desktop;
    text/html=firefox.desktop;abiword.desktop;calibre-ebook-edit.desktop;rstudio.desktop;elinks.desktop;
    text/javascript=rstudio.desktop;
    text/x-R=rstudio.desktop;
    text/x-markdown=rstudio.desktop;
    text/x-r=rstudio.desktop;
    text/x-r-{doc,markdown,history,html,presentation,profile,source,sweave}\
    =rstudio.desktop;
    text/x-tex=texstudio.desktop;gvim.desktop;rstudio.desktop;

no other files mentioned in XDG spec contain any occurrence of rstudio.

grepping for the text/plain MIME type, I obtain:

/etc/xdg/mimeapps.list : text/plain=medit.desktop;
/usr/share/applications/mimeinfo.cache : text/plain=medit.desktop;libreoffice-writer.desktop;gvim.desktop;abiword.desktop;
~/.local/share/applications/mimeapps.list : text/plain=gvim.desktop
~/.local/share/applications/mimeapps.list : text/plain=gvim.desktop;

1 Answer 1

3

Make the mime-info file

$ vi ~/.local/share/mime/packages/x-r-noweb.xml

$ cat ~/.local/share/mime/packages/x-r-noweb.xml
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="text/x-r-noweb">
        <comment>R noweb</comment>
        <glob pattern="*.Rnw"/>
    </mime-type>
</mime-info>

Update mime database

$ update-mime-database ~/.local/share/mime/

$ xdg-mime query filetype rnoweb0.Rnw 
text/x-r-noweb
$ mimetype -d rnoweb0.Rnw
rnoweb0.Rnw: R noweb
$ mimetype rnoweb0.Rnw
rnoweb0.Rnw: text/x-r-noweb

Now, you can set the default application

$ xdg-mime default nice-app.desktop text/x-r-noweb
# (or edit ~/.local/share/applications/mimeapps.list)

$ xdg-mime query default text/x-r-noweb
nice-app.desktop
1
  • Thanks! This file exists (/usr/share/mime/text/x-r-sweave.xml) and determines the description column in thunar an pcmanfm. The default application was set in /usr/share/applications/mimeinfo.cache. It works now! Only xdg-mime still reports something different (text/plain)
    – akraf
    Jun 19, 2015 at 8:30

You must log in to answer this question.

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