Skip to content

feat: let users override icons #562

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lua/nvim-web-devicons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ local function get_highlight_ctermfg(icon_data)

if vim.fn.has "nvim-0.9" == 1 then
--- @diagnostic disable-next-line: undefined-field vim.api.keyset.hl_info specifies cterm, not ctermfg
return vim.api.nvim_get_hl(0, { name = higroup, link = false }).ctermfg
return tostring(vim.api.nvim_get_hl(0, { name = higroup, link = false }).ctermfg)
else
return vim.api.nvim_get_hl_by_name(higroup, false).foreground ---@diagnostic disable-line: deprecated
return tostring(vim.api.nvim_get_hl_by_name(higroup, false).foreground) ---@diagnostic disable-line: deprecated
end
end

Expand Down Expand Up @@ -239,6 +239,7 @@ function M.setup(opts)
local user_operating_system_icons = user_icons.override_by_operating_system
local user_desktop_environment_icons = user_icons.override_by_desktop_environment
local user_window_manager_icons = user_icons.override_by_window_manager
local user_icon_overrides = user_icons.override_by_icon

-- filename matches are case insensitive
lowercase_keys(icons_by_filename)
Expand All @@ -253,7 +254,8 @@ function M.setup(opts)
user_file_ext_icons or {},
user_operating_system_icons or {},
user_desktop_environment_icons or {},
user_window_manager_icons or {}
user_window_manager_icons or {},
user_icon_overrides or {}
)
global_opts.override = vim.tbl_extend(
"force",
Expand All @@ -263,7 +265,8 @@ function M.setup(opts)
user_file_ext_icons or {},
user_operating_system_icons or {},
user_desktop_environment_icons or {},
user_window_manager_icons or {}
user_window_manager_icons or {},
user_icon_overrides or {}
)

if user_filename_icons then
Expand Down Expand Up @@ -356,6 +359,11 @@ local function get_icon_data(name, ext, opts)
icon_data = icons[name] or get_icon_by_extension(name, ext, opts) or (has_default and default_icon)
end

-- Check for icon override
if icon_data and global_opts.override[icon_data.icon] then
icon_data = vim.tbl_extend("force", icon_data, global_opts.override[icon_data.icon])
end

return icon_data
end

Expand Down
Loading