Function to test if a file is executable (755) or so

I have the following function

M.is_executable = function()
    local file = vim.fn.expand("%:p")
    local type = vim.fn.getftype(file)
    if type == "file" then
        local perm = vim.fn.getfperm(file)
        if string.match(perm, 'x', 3) then
            return true
        else
            return false
        end
    end
end

If you think you have a shorter (pure lua) or more efficient way of doing that I would like to see your solution!

In my autocommands.lua I have:

make_scripts_executable = {
    event = "BufWritePost",
    pattern = "*.sh,*.py,*.zsh,*.lua",
    callback = function()
       local status = require('core.utils').is_executable()
       if status ~= true then
          vim.fn.setfperm(vim.fn.expand("%:p"), "rwxr-x--x")
       end
    end
  }