feat(util): simple function to get an icon

This commit is contained in:
Folke Lemaitre 2024-12-01 09:06:52 +01:00
parent d517b11cab
commit 7c29848e89
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 35 additions and 12 deletions

View file

@ -52,4 +52,21 @@ function M.bo(buf, bo)
end
end
---@param name string
---@param cat? string
---@return string, string?
function M.icon(name, cat)
-- stylua: ignore
local try = {
function() return require("mini.icons").get(cat or "file", name) end,
function() return require("nvim-web-devicons").get_icon(name) end,
}
for _, fn in ipairs(try) do
local ret = { pcall(fn) }
if ret[1] then
return ret[2], ret[3]
end
end
return ""
end
return M