4

I have this file named "pom.xml" which I want to open with intellij ide and rest of the .xml files with gedit. Is it possible?

Somebody
  • 149
  • 1
    It is possible but I'll probably not have time to write an answer before Sunday. Maybe you can solve your problem yourself with this link. – danzel Jun 11 '20 at 18:07

2 Answers2

1

No, as such this is not possible. The reason is that default applications are associated to a specific mime type. In turn, a mime type is defined by a file extension. A file extension is defined as any characters coming after the last dot in the file name. Thus, applications can only be associated based on the file extension.

Workarounds

  • You could create a bash script (anywhere in your file system) that opens your file when double-clicking on it. In "Preferences" of "Files", "Behavior" tab, you will need to change the option for "Executable Text Files" to "Run them" for this to work.
  • You could create a launcher on the desktop or in your application menu that opens the specific file in the specific application. In recent Ubuntu versions, it is not anymore possible by default to run a .desktop file directly from your file manager
  • You could give the file a different extension and then create your own mime type for it, and assign a different default application.
vanadium
  • 88,010
1

Yes, this is possible.

As @vanadium correctly pointed out, default applications are bound to mime types. However, those mime types are not bound to file extensions. There are complex algorithms that take into account filesystem specifics (e.g. regular file or symlink), filename (e.g. file extension), and file contents (binary, ASCII, ...) in order to determine the mime type of a file. In essence, the mime type is an abstract desription of the file's contents.

So now the question boils down to "how do I make pom.xml have a different mime type than any other *.xml"?

Luckily, you can define your own mime types. The following instructions are from here:

Assuming that you want to change the behavior for your user only, create the following file:

~/.local/share/mime/packages/application-xml-pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="application/xml-pom">
        <comment>Maven Project Object Model</comment>
        <icon name="application-xml"/>
        <glob-deleteall/>
        <glob pattern="pom.xml"/>
    </mime-type>
</mime-info>

Update the mime type database:

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

That mime type will only match files called pom.xml.

Now you can associate an application with the newly created mime type in your favorite file manager.

danzel
  • 6,044