Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to add/override icons for filetypes #406

Closed
classabbyamp opened this issue Feb 27, 2024 · 4 comments · Fixed by #407
Closed

No way to add/override icons for filetypes #406

classabbyamp opened this issue Feb 27, 2024 · 4 comments · Fixed by #407

Comments

@classabbyamp
Copy link
Contributor

classabbyamp commented Feb 27, 2024

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
Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Contributor Author

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

@alex-courtis
Copy link
Member

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

Yes please - completely override or add.

alex-courtis pushed a commit that referenced this issue Mar 2, 2024
simply adds/updates user-defined filetypes to the internal filetypes
table.

fixes #406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants