From 6172de22b7c8bf86d626cf02ee1a6f1365f6a445 Mon Sep 17 00:00:00 2001 From: Luis Simas Date: Mon, 31 May 2021 20:29:15 -0300 Subject: [PATCH 1/2] Improve icon fetching by file extension --- lua/nvim-tree/populate.lua | 2 +- lua/nvim-tree/renderer.lua | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/populate.lua b/lua/nvim-tree/populate.lua index 0b92e5ed7ad..823fab4e9af 100644 --- a/lua/nvim-tree/populate.lua +++ b/lua/nvim-tree/populate.lua @@ -46,7 +46,7 @@ local function file_new(cwd, name) name = name, absolute_path = absolute_path, executable = is_exec, - extension = vim.fn.fnamemodify(name, ':e') or "", + extension = string.match(name, "%.(.*)") or "", match_name = path_to_matching_str(name), match_path = path_to_matching_str(absolute_path), } diff --git a/lua/nvim-tree/renderer.lua b/lua/nvim-tree/renderer.lua index 6bde049b74e..68ed6acf930 100644 --- a/lua/nvim-tree/renderer.lua +++ b/lua/nvim-tree/renderer.lua @@ -58,11 +58,14 @@ if icon_state.show_file_icon then get_file_icon = function(fname, extension, line, depth) local icon, hl_group = web_devicons.get_icon(fname, extension) - if icon then + if icon and hl_group ~= "DevIconDefault" then if hl_group then table.insert(hl, { hl_group, line, depth, depth + #icon + 1 }) end return icon.." " + elseif string.match(extension, "%.(.*)") then + -- If there are more extensions to the file, try to grab the icon for them recursively + return get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth) else return #icon_state.icons.default > 0 and icon_state.icons.default.." " or "" end From b54113105b1d843d5c1af6b6b3568eb5ada7506e Mon Sep 17 00:00:00 2001 From: Luis Simas Date: Tue, 1 Jun 2021 11:59:28 -0300 Subject: [PATCH 2/2] fix: extension pattern no longer matches dotfiles This new pattern suggested by @sindrets is way better in the sense that it doesn't match dotfiles as if they were extensions. --- lua/nvim-tree/populate.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/populate.lua b/lua/nvim-tree/populate.lua index 823fab4e9af..a955736869b 100644 --- a/lua/nvim-tree/populate.lua +++ b/lua/nvim-tree/populate.lua @@ -46,7 +46,7 @@ local function file_new(cwd, name) name = name, absolute_path = absolute_path, executable = is_exec, - extension = string.match(name, "%.(.*)") or "", + extension = string.match(name, ".?[^.]+%.(.*)") or "", match_name = path_to_matching_str(name), match_path = path_to_matching_str(absolute_path), }