Skip to content

Commit 2e106b7

Browse files
folliehiyukidlyongemallo
authored andcommitted
feat: add mini.icons support as file icons provider (sindrets#571)
Add support for mini.icons as an alternative to nvim-web-devicons for file icons. The plugin will try nvim-web-devicons first, then fall back to mini.icons if available.
1 parent bc08967 commit 2e106b7

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ for any git rev.
1818
- Git ≥ 2.31.0 (for Git support)
1919
- Mercurial ≥ 5.4.0 (for Mercurial support)
2020
- Neovim ≥ 0.7.0 (with LuaJIT)
21-
- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) (optional) For file icons
21+
- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) or [mini.icons](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-icons.md) (optional) for file icons
2222

2323
## Installation
2424

doc/diffview_defaults.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DEFAULT CONFIG *diffview.defaults*
77
enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl|
88
git_cmd = { "git" }, -- The git executable followed by default args.
99
hg_cmd = { "hg" }, -- The hg executable followed by default args.
10-
use_icons = true, -- Requires nvim-web-devicons
10+
use_icons = true, -- Requires nvim-web-devicons or mini.icons
1111
show_help_hints = true, -- Show hints for how to open the help panel
1212
watch_index = true, -- Update views and index buffers when the git index changes.
1313
icons = { -- Only applies when use_icons is true.

lua/diffview/health.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ M.plugin_deps = {
1919
name = "nvim-web-devicons",
2020
optional = true,
2121
},
22+
{
23+
name = "mini.icons",
24+
optional = true,
25+
},
2226
}
2327

2428
---@param cmd string|string[]

lua/diffview/hl.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local config = lazy.require("diffview.config") ---@module "diffview.config"
44
local utils = lazy.require("diffview.utils") ---@module "diffview.utils"
55

66
local api = vim.api
7-
local web_devicons
7+
local web_devicons, mini_icons
88
local icon_cache = {}
99

1010
local M = {}
@@ -349,14 +349,19 @@ end
349349
function M.get_file_icon(name, ext, render_data, line_idx, offset)
350350
if not config.get_config().use_icons then return "" end
351351

352-
if not web_devicons then
352+
if not (web_devicons or mini_icons) then
353353
local ok
354354
ok, web_devicons = pcall(require, "nvim-web-devicons")
355355

356+
if not ok then
357+
ok, mini_icons = pcall(require, "mini.icons")
358+
web_devicons = nil
359+
end
360+
356361
if not ok then
357362
config.get_config().use_icons = false
358363
utils.warn(
359-
"nvim-web-devicons is required to use file icons! "
364+
"nvim-web-devicons or mini.icons is required to use file icons! "
360365
.. "Set `use_icons = false` in your config to stop seeing this message."
361366
)
362367

@@ -369,9 +374,12 @@ function M.get_file_icon(name, ext, render_data, line_idx, offset)
369374

370375
if icon_cache[icon_key] then
371376
icon, hl = unpack(icon_cache[icon_key])
372-
else
377+
elseif web_devicons then
373378
icon, hl = web_devicons.get_icon(name, ext, { default = true })
374379
icon_cache[icon_key] = { icon, hl }
380+
else
381+
icon, hl = mini_icons.get("file", name)
382+
icon_cache[icon_key] = { icon, hl }
375383
end
376384

377385
if icon then

0 commit comments

Comments
 (0)