mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
update the enabled and config for telescope media files
This commit is contained in:
parent
793b2e4b1d
commit
92cf882f42
1 changed files with 42 additions and 51 deletions
|
|
@ -10,6 +10,34 @@ return {
|
||||||
return false
|
return false
|
||||||
end
|
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 = ""
|
local findCmd = ""
|
||||||
--- @class Set A simple Set implementation using a table to avoid duplicates; it only contains the methods add and toList
|
--- @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.
|
--- @field _data table<string, 1> Table to hold the set data.
|
||||||
|
|
@ -29,59 +57,24 @@ return {
|
||||||
return vim.tbl_keys(self._data)
|
return vim.tbl_keys(self._data)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function disableWithWarnMessage(msg)
|
-- Find the installed 'find' command
|
||||||
LazyVim.warn(
|
for _, cmd in ipairs({ "find", "fd", "rg" }) do
|
||||||
"You have enabled extras.editor.medias, see (:`LazyExtras`). \n\n"
|
if vim.fn.executable(cmd) == 1 then
|
||||||
.. msg
|
findCmd = cmd
|
||||||
.. "\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
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not findCmd then
|
-- Add the supported file types if the tool is installed
|
||||||
return disableWithWarnMessage(
|
local tools = {
|
||||||
"None of the required 'find cmd' prerequisites is installed.\n"
|
{ cmd = "chafa", name = "Chafa", filetypes = { "png", "jpg", "jpeg", "webp" } },
|
||||||
.. "Please install at least one of the following: `rd`, `rg`, or `find`."
|
{ cmd = "convert", name = "ImageMagick", filetypes = { "svg" } },
|
||||||
)
|
{ cmd = "ffmpegthumbnailer", name = "ffmpegthumbnailer", filetypes = { "mp4", "webm" } },
|
||||||
end
|
{ cmd = "pdftoppm", name = "pdftoppm", filetypes = { "pdf" } },
|
||||||
|
{ cmd = "epub-thumbnailer", name = "epub-thumbnailer", filetypes = { "epub" } },
|
||||||
-- Check optional prerequisites and include their filetypes if installed
|
{ cmd = "fontpreview", name = "fontpreview", filetypes = { "ttf", "otf" } },
|
||||||
for _, tool in ipairs(prerequisites.optional) do
|
}
|
||||||
|
for _, tool in ipairs(tools) do
|
||||||
if vim.fn.executable(tool.cmd) == 1 then
|
if vim.fn.executable(tool.cmd) == 1 then
|
||||||
supportedFiletypeSet:add(tool.filetypes)
|
supportedFiletypeSet:add(tool.filetypes)
|
||||||
end
|
end
|
||||||
|
|
@ -99,8 +92,6 @@ return {
|
||||||
LazyVim.error("Failed to load telescope.nvim")
|
LazyVim.error("Failed to load telescope.nvim")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return true
|
|
||||||
end,
|
end,
|
||||||
keys = {
|
keys = {
|
||||||
{ "<leader>fP", "<cmd>Telescope media_files<cr>", desc = "Find Media Files" },
|
{ "<leader>fP", "<cmd>Telescope media_files<cr>", desc = "Find Media Files" },
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue