update the enabled and config for telescope media files

This commit is contained in:
arthur 2024-06-14 11:05:40 +08:00
parent 793b2e4b1d
commit 92cf882f42

View file

@ -10,6 +10,34 @@ return {
return false
end
local function disableWithWarnMessage(msg)
LazyVim.warn(
"You have enabled extras.editor.medias, see (:`LazyExtras`). \n\n"
.. msg
.. "\n\nMore information can be found at: "
.. "[nvim-telescope/telescope-media-files.nvim](https://github.com/nvim-telescope/telescope-media-files.nvim?tab=readme-ov-file#prerequisites)."
)
return false
end
if vim.fn.executable("chafa") == 0 then
return disableWithWarnMessage("The required prerequisite not installed: `Chafa`")
end
local hasFindCmd = vim.tbl_contains({ "find", "fd", "rg" }, function(cmd)
return vim.fn.executable(cmd) == 1
end, { predicate = true })
if not hasFindCmd then
return disableWithWarnMessage(
"None of the required 'find cmd' prerequisites is installed.\n"
.. "Please install at least one of the following: `rd`, `rg`, or `find`."
)
end
return true
end,
config = function()
local findCmd = ""
--- @class Set A simple Set implementation using a table to avoid duplicates; it only contains the methods add and toList
--- @field _data table<string, 1> Table to hold the set data.
@ -29,59 +57,24 @@ return {
return vim.tbl_keys(self._data)
end
local function disableWithWarnMessage(msg)
LazyVim.warn(
"You have enabled extras.editor.medias, see (:`LazyExtras`). \n\n"
.. msg
.. "\n\nMore information can be found at: "
.. "[nvim-telescope/telescope-media-files.nvim](https://github.com/nvim-telescope/telescope-media-files.nvim?tab=readme-ov-file#prerequisites)."
)
return false
end
local prerequisites = {
required = {
{ cmd = "chafa", name = "Chafa", filetypes = { "png", "jpg", "jpeg", "webp" } },
},
findCmd = {
{ cmd = "fd", name = "fd" },
{ cmd = "rg", name = "rg" },
{ cmd = "find", name = "find" },
},
optional = {
{ cmd = "convert", name = "ImageMagick", filetypes = { "svg" } },
{ cmd = "ffmpegthumbnailer", name = "ffmpegthumbnailer", filetypes = { "mp4", "webm" } },
{ cmd = "pdftoppm", name = "pdftoppm", filetypes = { "pdf" } },
{ cmd = "epub-thumbnailer", name = "epub-thumbnailer", filetypes = { "epub" } },
{ cmd = "fontpreview", name = "fontpreview", filetypes = { "ttf", "otf" } },
},
}
-- Ensure all required prerequisites are installed
for _, tool in ipairs(prerequisites.required) do
if vim.fn.executable(tool.cmd) == 0 then
return disableWithWarnMessage(string.format("The required prerequisite not installed: `%s`", tool.name))
else
supportedFiletypeSet:add(tool.filetypes)
end
end
-- Verify that at least one of the required find commands is installed
for _, tool in ipairs(prerequisites.findCmd) do
if vim.fn.executable(tool.cmd) == 1 then
findCmd = tool.cmd
-- Find the installed 'find' command
for _, cmd in ipairs({ "find", "fd", "rg" }) do
if vim.fn.executable(cmd) == 1 then
findCmd = cmd
break
end
end
if not findCmd then
return disableWithWarnMessage(
"None of the required 'find cmd' prerequisites is installed.\n"
.. "Please install at least one of the following: `rd`, `rg`, or `find`."
)
end
-- Check optional prerequisites and include their filetypes if installed
for _, tool in ipairs(prerequisites.optional) do
-- Add the supported file types if the tool is installed
local tools = {
{ cmd = "chafa", name = "Chafa", filetypes = { "png", "jpg", "jpeg", "webp" } },
{ cmd = "convert", name = "ImageMagick", filetypes = { "svg" } },
{ cmd = "ffmpegthumbnailer", name = "ffmpegthumbnailer", filetypes = { "mp4", "webm" } },
{ cmd = "pdftoppm", name = "pdftoppm", filetypes = { "pdf" } },
{ cmd = "epub-thumbnailer", name = "epub-thumbnailer", filetypes = { "epub" } },
{ cmd = "fontpreview", name = "fontpreview", filetypes = { "ttf", "otf" } },
}
for _, tool in ipairs(tools) do
if vim.fn.executable(tool.cmd) == 1 then
supportedFiletypeSet:add(tool.filetypes)
end
@ -99,8 +92,6 @@ return {
LazyVim.error("Failed to load telescope.nvim")
end
end)
return true
end,
keys = {
{ "<leader>fP", "<cmd>Telescope media_files<cr>", desc = "Find Media Files" },