diff --git a/README.md b/README.md index 3d037f01..afdd0f3f 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Grug find! Grug replace! Grug happy! - [BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) >= 14 recommended - a [Nerd Font](https://www.nerdfonts.com/) **_(optional)_** - [ast-grep](https://ast-grep.github.io) **_(optional)_** if you would like to use the `ast-grep` search engine. Version >= `0.25.7` if you would like context lines flags to work. +- either [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) or [mini.icons](https://github.com/echasnovski/mini.icons) for file icons support **_(optional)_** Run `:checkhealth grug-far` if you see unexpected issues. diff --git a/lua/grug-far/fileIconsProvider.lua b/lua/grug-far/fileIconsProvider.lua index b96c35ce..15639c9d 100644 --- a/lua/grug-far/fileIconsProvider.lua +++ b/lua/grug-far/fileIconsProvider.lua @@ -11,8 +11,8 @@ local providers = { { type = 'nvim-web-devicons', get_lib = function() - local _, lib = pcall(require, 'nvim-web-devicons') - if not lib then + local found, lib = pcall(require, 'nvim-web-devicons') + if not found then return nil end @@ -24,6 +24,14 @@ local providers = { return lib end, get_icon = function(self, path) + -- first, try to match extensions like .spec.js + local basename = vim.fs.basename(path) + local multi_dot_extension = basename:match('[^.]*%.(.+)$') + local icon, hl = self._lib.get_icon(path, multi_dot_extension, { default = false }) + if icon then + return icon, hl + end + local extension = string.match(path, '.+%.(.+)$') return self._lib.get_icon(path, extension, { default = true }) end, @@ -31,12 +39,14 @@ local providers = { { type = 'mini.icons', get_lib = function() - local _, lib = pcall(require, 'mini.icons') - if not lib then + local found, lib = pcall(require, 'mini.icons') + if not found then return nil end -- according to mini.icons docs, need to check this -- to make sure setup has been called! + -- selene: allow(global_usage) + ---@diagnostic disable-next-line if not _G.MiniIcons then return nil end diff --git a/lua/grug-far/opts.lua b/lua/grug-far/opts.lua index 8913c5e7..08367972 100644 --- a/lua/grug-far/opts.lua +++ b/lua/grug-far/opts.lua @@ -182,7 +182,7 @@ M.defaultOptions = { -- whether to show icons enabled = true, - -- provider to use for file icons. + -- provider to use for file icons -- acceptable values: 'first_available', 'nvim-web-devicons', 'mini.icons', false (to disable) fileIconsProvider = 'first_available',