Replies: 13 comments
-
Hi, regexes are not supported at the moment, i think this could be added as a feature if it doesn't impact performance. |
Beta Was this translation helpful? Give feedback.
-
I get it, it would be great if that feature was added. |
Beta Was this translation helpful? Give feedback.
-
I agree, ill see when I have some time to implement this |
Beta Was this translation helpful? Give feedback.
-
@kyazdani42 Is it possible to add a icon for a extension like |
Beta Was this translation helpful? Give feedback.
-
i'm not sure what's your question here @reportaman ? could you be a little bit more specific please ? |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm not sure if this is exactly what @Fenriuz means, but I was looking for a similar behaviour while using nvim-tree, and in the process of trying to implement it I may have found something that works. I couldn't find a good way of implementing it in nvim-web-devicons itself, the way that the @kyazdani42, I see that nvim-tree uses the What I did was change the require("nvim-web-devicons").setup {
override = {
["test.js"] = {
icon = "ﭧ",
color = "#cbcb41",
name = "JavascriptTest"
}
},
default = true
} The problem is that I don't know if this will break anything in nvim-tree, so I would like to ask @kyazdani42's opinion on this. This is far from being the regex-like feature, but I think it covers some use cases that are very common. If it's ok I can submit a PR to nvim-tree and then add some icons and doc regarding this behaviour to this repo later. |
Beta Was this translation helpful? Give feedback.
-
hi @luissimas, send a PR and i'll do a set of personnal test to ensure it's working as expected. It might break icon display for certain filenames but i'm not sure as i haven't seen your implementation yet :) |
Beta Was this translation helpful? Give feedback.
-
regexes would be a great feature. 👍 Like it is now we have to
I suppose I will stick with our naming for now until we get regexes in this library. Great pull-request from @luissimas 🥇 that matches all dots in the end of the string. Keep up the good work @kyazdani42 💯 and thanks for bringing us this library. |
Beta Was this translation helpful? Give feedback.
-
For test files you can do: local devicons = require "nvim-web-devicons"
local function get_ext(name)
if name:find "^.+%.test%..+$" or name:find "^.+Test%..+$" or name:find "^.+_test%..+$" then
return "test"
end
if name:find "^.+%.spec%..+$" or name:find "^.+Spec%..+$" or name:find "^.+_spec%..+$" then
return "spec"
end
return name:match "^.*%.(.*)$" or ""
end
local get_icon = devicons.get_icon
devicons.get_icon = function(name, ext, opts)
return get_icon(name, ext or get_ext(name), opts)
end
local get_icon_colors = devicons.get_icon_colors
devicons.get_icon_colors = function(name, ext, opts)
return get_icon_colors(name, ext or get_ext(name), opts)
end
devicons.setup {
override = {
["test"] = { icon = "ﭧ", color = "#cbcb41", name = "TestFile" },
["spec"] = { icon = "ﭧ", color = "#cbcb41", name = "SpecFile" },
},
} Example: HelloTest.php
hello.test.js
hello_test.go |
Beta Was this translation helpful? Give feedback.
-
Can this also be done for files that contain "env" in their name? Or generally user defined regex filters?
|
Beta Was this translation helpful? Give feedback.
-
Unfortunately we don't have regex support. You can add your own specific icons via API: https://github.com/nvim-tree/nvim-web-devicons#set-an-icon |
Beta Was this translation helpful? Give feedback.
-
I had a similar issue but with files of the type local function get_special_ext(name)
if name:find(".*%.gitlab%-ci.*%.yml") then -- Match <>.gitlab-ci<>.yml
return "gitlab-ci.yml" -- Return `gitlab-ci.yml` as the extension
end
return nil
end
local devicons = require("nvim-web-devicons")
local get_icon = devicons.get_icon
devicons.get_icon = function(name, ext, opts)
return get_icon(name, get_special_ext(name) or ext, opts)
end
local get_icon_colors = devicons.get_icon_colors
devicons.get_icon_colors = function(name, ext, opts)
return get_icon_colors(name, get_special_ext(name) or ext, opts)
end The thing is, files like This also requires that, by default, |
Beta Was this translation helpful? Give feedback.
-
Forgot to add - I also defined a "custom extension" ( devicons.setup({
-- [...]
override_by_extension = {
["gitlab-ci.yml"] = <my custom icon>
},
})
|
Beta Was this translation helpful? Give feedback.
-
How to add an icon for certain extensions?
I don't really know how to formulate my question, but with devicons I could do this
let g: WebDevIconsUnicodeDecorateFileNodesPatternSymbols ['. * Test. * \. Js $'] = 'ﭧ'
And the result was the following:
How can I achieve the same result with this plugin?
Beta Was this translation helpful? Give feedback.
All reactions