diff --git a/lua/lazyvim/plugins/extras/editor/medias.lua b/lua/lazyvim/plugins/extras/editor/medias.lua index d885563e..223c4c4c 100644 --- a/lua/lazyvim/plugins/extras/editor/medias.lua +++ b/lua/lazyvim/plugins/extras/editor/medias.lua @@ -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 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 = { { "fP", "Telescope media_files", desc = "Find Media Files" },