0

I'm encountering an error similar to xdg-mime-install-does-not-update-files-mime-type-association and why-does-xdg-mime-query-filetype-fail-to-find-a-new-added-file-type

But the solution to the first one is to add some content to the file which does not to work.

And the solution to the second link is not complete since I have xdg-utils installed, And I don't know much about this magic file. I have read man for magic (it refers to /usr/share/file/misc/magic and /usr/share/file/misc/magic.mgc which is not the same as ~/.local/share/mime/magic or /usr/share/mime/magic and it doesn't provide steps to add a filetype to it (I must have missed it or else))

My error still stands even after adding text to that file. To be specific, a .lua file.

Steps I have taken:

  1. In ~/.local/share/mime/packages I created a .xml file with the following contents,
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="hhttp://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="text/x-lua">
        <comment>Lua scirpt</comment>
        <glob-deleteall/>
        <glob pattern="*.lua"/>
    </mime-type>
</mime-info>
  1. run xdg-mime install text-x-lua.xml
  2. run update-mime-database ~/.local/share/mime
  3. run the following
$ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime default nvim.desktop text/x-lua
make_default_kde: No kde runtime detected
make_default_generic nvim.desktop text/x-lua
Updating /home/boom29/.config/mimeapps.list
$ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default text/x-lua
Checking /home/boom29/.config/mimeapps.list
nvim.desktop

But these steps do not reflect in practice, xdg-mime filetypes do not update.

For example:

$ cat test.lua 
-- defines a factorial function
    function fact (n)
      if n == 0 then
        return 1
      else
        return n * fact(n-1)
      end
    end
    
    print("enter a number:")
    a = io.read("*number")        -- read a number
    print(fact(a))
$ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query filetype test.lua
Running file --brief --dereference --mime-type "/home/boom29/test.lua"
text/plain

Any help is appreciated.

EDIT:

$ cat init.lua
require("core.keymaps")
$ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query filetype init.lua 
Running file --brief --dereference --mime-type "/home/boom29/.config/nvim/init.lua"
application/javascript

Why is a .lua file being recognized as a javascript file?

1
  • What is the contents of $HOME/.config/mimeapps.list? Commented Jul 12, 2024 at 13:08

1 Answer 1

0

The source code to the command file(1) used in Arch Linux was modified in February 2024, removing the pattern to recognize a file whose contents match the regex \^require\\(["'] as JavaScript, precisely to avoid detecting Lua files as JavaScript. The pattern was being set up with strength 30:

!:strength +30
!:mime  application/javascript
!:ext   js
0   regex   \^require\\(["']    JavaScript source

so it would override the pattern for Lua script, which examines the shebang:

# Lua scripts
0   search/1/w  #!\ /usr/bin/lua    Lua script text executable
!:mime  text/x-lua
0   search/1/w  #!\ /usr/local/bin/lua  Lua script text executable
!:mime  text/x-lua
0   search/1    #!/usr/bin/env\ lua Lua script text executable
!:mime  text/x-lua
0   search/1    #!\ /usr/bin/env\ lua   Lua script text executable
!:mime  text/x-lua

Quoting the commit message:

remove ^require pattern. require is a node.js method that returns a value and this pattern can be confused with lua.

You either don't have the latest version of file package installed, or Arch Linux still hasn't caught up with this commit. Running

pacman -Syu

as root would rule out the first possibility, so if after running that command you still experience the issue, contact the maintainer of that Arch package.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.