Skip to content

Commit

Permalink
fix(#502): explicit case insensitive matching of filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Oct 4, 2024
1 parent 6b53401 commit affeb50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 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
23 changes: 23 additions & 0 deletions lua/nvim-web-devicons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,24 @@ 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
---@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
t[lower_k] = v
t[k] = nil
end
end
end
end

local loaded = false

function M.has_loaded()
Expand Down Expand Up @@ -396,6 +414,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

0 comments on commit affeb50

Please sign in to comment.