如何将 shell 脚本注册为给定文件扩展名的主应用程序

jul*_*ien 7 file-format file-association

我有一个 shell 脚本“the_script”,我想将其注册为扩展名为“.ext”的文件的默认应用程序。为此,我编写了一个 xml 文件来注册 mime 类型,并编写了一个 .desktop 文件来将应用程序与 mime 类型相关联。该脚本具有用户的可执行位,并且在用户路径中可用。

名为“the_script.xml”的xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="application/x-the-script">
        <comment>A file for the script</comment>
        <glob pattern="*.ext"/>
    </mime-type>
</mime-info>
Run Code Online (Sandbox Code Playgroud)

然后我跑了xdg-mime install --novendor the_script.xml

名为“the_script.desktop”的 .desktop 文件如下:

[Desktop Entry]
Version=1.0

Type=Application
MimeType=application/x-the-script

Name=The script that manages .ext files

Comment=Interpreter for .ext files

TryExec=the_script
Exec=the_script %f
Terminal=false
Run Code Online (Sandbox Code Playgroud)

我跑去xdg-desktop-menu install --novendor the_script.desktop注册文件。

一旦注册了这两个文件,.ext 文件就不再使用文本编辑器打开,但 Gnome 告诉我没有安装文件“脚本文件”的应用程序。

我已经在其他应用程序中成功注册了其他文件格式。其他应用程序是编译程序,而 the_script 是一个 shell 脚本。这是我能看到的唯一区别。如何使用 .ext 文件注册我的脚本?

hto*_*que 4

如果您这样做,这似乎可以在终端上正常工作xdg-open foo.ext,但是它似乎在 Nautilus 中不起作用,除非您将脚本定义为打开 *.ext 文件的默认脚本:

  • 选择这样一个文件,
  • 右键点击,
  • 选择属性
  • 选择打开方式选项卡,
  • 单击显示其他应用程序
  • 选择您的脚本(应该是管理 .ext 文件的脚本),
  • 单击设置为默认值,最后按
  • 关闭

完成此操作后,脚本从 Nautilus 开始。