nvim-tree / nvim-web-devicons

lua `fork` of vim-web-devicons for neovim
MIT License
1.93k stars 182 forks source link

No way to add/override icons for filetypes #406

Closed classabbyamp closed 4 months ago

classabbyamp commented 4 months ago

the get_icon_*_by_filetype api relies on the filetypes local, which cannot be extended or modified externally. this makes it impossible to add an icon for a custom filetype, and because lualine uses the _by_filetype api, it cannot use any custom icons.

would it be possible to add a set_icon_by_filetype or make filetypes publicly accessible?

classabbyamp commented 4 months ago

this solves my issue

diff --git a/lua/nvim-web-devicons.lua b/lua/nvim-web-devicons.lua
index 4301079..d8b6a73 100644
--- a/lua/nvim-web-devicons.lua
+++ b/lua/nvim-web-devicons.lua
@@ -39,7 +39,7 @@ local function refresh_icons()
 end

 -- Map of filetypes -> icon names
-local filetypes = {
+M.filetypes = {
   ["avif"] = "avif",
   ["bzl"] = "bzl",
   ["brewfile"] = "brewfile",
@@ -437,7 +437,7 @@ function M.get_icon(name, ext, opts)
 end

 function M.get_icon_name_by_filetype(ft)
-  return filetypes[ft]
+  return M.filetypes[ft]
 end

 function M.get_icon_by_filetype(ft, opts)

by allowing me to do require("nvim-web-devicons").filetypes["srcpkg"] = "void"

would that be an acceptable change to PR?

alex-courtis commented 4 months ago

That would be great.

Let's use a setter set_icon_by_filetype please instead of exposing the internals.

Confirmed: no action will be needed in the case of colourscheme change etc.

classabbyamp commented 4 months ago

but inside the setter, that mechanism is the way to go?

alex-courtis commented 4 months ago

but inside the setter, that mechanism is the way to go?

Yes please - completely override or add.