Skip to content

Commit

Permalink
allowing for multidot extensions like .spec.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicDuck committed Sep 6, 2024
1 parent 36c5f5f commit 8b963f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
18 changes: 14 additions & 4 deletions lua/grug-far/fileIconsProvider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,19 +24,29 @@ 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,
},
{
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
Expand Down
2 changes: 1 addition & 1 deletion lua/grug-far/opts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down

0 comments on commit 8b963f5

Please sign in to comment.