Skip to content

Commit

Permalink
fix(#502): explicit case insensitive matching of filenames (#503)
Browse files Browse the repository at this point in the history
* fix(#502): explicit case insensitive matching of filenames

* fix(#502): explicit case insensitive matching of filenames

* fix(#502): explicit case insensitive matching of filenames

* fix(#502): explicit case insensitive matching of filenames
  • Loading branch information
alex-courtis authored Oct 4, 2024
1 parent 6b53401 commit 56f17de
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ The variant is updated:

However, be advised that the plugin using nvim-web-devicons may have cached the icons.

### Case Sensitivity

Filename icons e.g. `"Dockerfile"` are case insensitively matched.

Extension icons e.g. `"lua"` are case sensitive.

### Setup

This adds all the highlight groups for the devicons
Expand Down
26 changes: 26 additions & 0 deletions lua/nvim-web-devicons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,27 @@ local function get_highlight_ctermfg(icon_data)
return nvim_get_hl_by_name(get_highlight_name(icon_data), false).foreground
end

---Change all keys in a table to lowercase
---Remove entry when lowercase entry already exists
---@param t table
local function lowercase_keys(t)
if not t then
return
end

for k, v in pairs(t) do
if type(k) == "string" then
local lower_k = k:lower()
if lower_k ~= k then
if not t[lower_k] then
t[lower_k] = v
end
t[k] = nil
end
end
end
end

local loaded = false

function M.has_loaded()
Expand Down Expand Up @@ -396,6 +417,11 @@ function M.setup(opts)
local user_desktop_environment_icons = user_icons.override_by_desktop_environment
local user_window_manager_icons = user_icons.override_by_window_manager

-- filename matches are case insensitive
lowercase_keys(icons_by_filename)
lowercase_keys(user_icons.override)
lowercase_keys(user_icons.override_by_filename)

icons = vim.tbl_extend(
"force",
icons,
Expand Down
12 changes: 0 additions & 12 deletions lua/nvim-web-devicons/icons-default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,6 @@ local icons_by_filename = {
cterm_color = "28",
name = "Vimrc",
},
["R"] = {
icon = "󰟔",
color = "#2266ba",
cterm_color = "25",
name = "R",
},
["avif"] = {
icon = "",
color = "#a074c4",
Expand Down Expand Up @@ -833,12 +827,6 @@ local icons_by_filename = {
cterm_color = "77",
name = "Qt",
},
["r"] = {
icon = "󰟔",
color = "#2266ba",
cterm_color = "25",
name = "R",
},
["rakefile"] = {
icon = "",
color = "#701516",
Expand Down
12 changes: 0 additions & 12 deletions lua/nvim-web-devicons/icons-light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,6 @@ local icons_by_filename = {
cterm_color = "22",
name = "Vimrc",
},
["R"] = {
icon = "󰟔",
color = "#1a4c8c",
cterm_color = "25",
name = "R",
},
["avif"] = {
icon = "",
color = "#6b4d83",
Expand Down Expand Up @@ -833,12 +827,6 @@ local icons_by_filename = {
cterm_color = "28",
name = "Qt",
},
["r"] = {
icon = "󰟔",
color = "#1a4c8c",
cterm_color = "25",
name = "R",
},
["rakefile"] = {
icon = "",
color = "#701516",
Expand Down

0 comments on commit 56f17de

Please sign in to comment.