[File] lua file detected as javascript
Avid Seeker
avidseeker at disroot.org
Mon Apr 14 18:02:12 UTC 2025
$ wget 'https://raw.githubusercontent.com/ibhagwan/fzf-lua/refs/heads/main/lua/fzf-lua/defaults.lua'
&& file defaults.lua
Expected text/plain but file reads that as: `defaults.lua: JavaScript source,
Unicode text, UTF-8 text`
I reached the following as a minimal reproducible example. If the last
function is deleted, the file is detected as text/plain.
```
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
local actions = require "fzf-lua.actions"
local previewers = require "fzf-lua.previewer"
local M = {}
function M._default_previewer_fn()
local winopts = M.globals.winopts
if type(winopts) == "function" then
winopts = winopts() or {}
winopts.preview = type(winopts.preview) == "table" and winopts.preview or {}
winopts.preview.default = winopts.preview.default or M.defaults.winopts.preview.default
end
local previewer = M.globals.default_previewer or winopts.preview.default
-- the setup function cannot have a custom previewer as deepcopy
-- fails with stack overflow while trying to copy the custom class
-- the workaround is to define the previewer as a function instead
-- https://github.com/ibhagwan/fzf-lua/issues/677
return type(previewer) == "function" and previewer() or previewer
end
function M._preview_pager_fn()
return vim.fn.executable("delta") == 1 and ("delta --width=$COLUMNS --%s"):format(vim.o.bg) or
nil
end
function M._man_cmd_fn(bat_pager)
local cmd = utils.is_darwin() and "man -P cat"
or vim.fn.executable("mandb") == 1 and "man"
or "man -c"
local bat_cmd = bat_pager and (function()
for _, bin in ipairs({ "batcat", "bat" }) do
if vim.fn.executable(bin) == 1 then
return string.format("%s --color=always -p -l man", bin)
end
end
end)()
local pager = bat_cmd or "col -bx"
return string.format("%s %%s 2>/dev/null | %s", cmd, pager)
end
```
More information about the File
mailing list