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
  }

Try this, it is not a pure lua way but is more concise.
I went by the GNU philosophy of let a program do just 1 thing. So I used file which does exactly what you wanted and brought its output to neovim.

local function is_executable(file)
  local v = vim.api.nvim_exec2("!file " .. file, {output = true})
  if string.find(v.output, "executable", 0, true) then
    return true;
  else
    return false;
  end
end