Skip to content

Add support for mini.icons as a file icons provider #571

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for any git rev.
- Git ≥ 2.31.0 (for Git support)
- Mercurial ≥ 5.4.0 (for Mercurial support)
- Neovim ≥ 0.7.0 (with LuaJIT)
- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) (optional) For file icons
- [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

## Installation

Expand Down
2 changes: 1 addition & 1 deletion doc/diffview_defaults.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DEFAULT CONFIG *diffview.defaults*
enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl|
git_cmd = { "git" }, -- The git executable followed by default args.
hg_cmd = { "hg" }, -- The hg executable followed by default args.
use_icons = true, -- Requires nvim-web-devicons
use_icons = true, -- Requires nvim-web-devicons or mini.icons
show_help_hints = true, -- Show hints for how to open the help panel
watch_index = true, -- Update views and index buffers when the git index changes.
icons = { -- Only applies when use_icons is true.
Expand Down
4 changes: 4 additions & 0 deletions lua/diffview/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ M.plugin_deps = {
name = "nvim-web-devicons",
optional = true,
},
{
name = "mini.icons",
optional = true,
},
}

---@param cmd string|string[]
Expand Down
16 changes: 12 additions & 4 deletions lua/diffview/hl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local config = lazy.require("diffview.config") ---@module "diffview.config"
local utils = lazy.require("diffview.utils") ---@module "diffview.utils"

local api = vim.api
local web_devicons
local web_devicons, mini_icons
local icon_cache = {}

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

if not web_devicons then
if not (web_devicons or mini_icons) then
local ok
ok, web_devicons = pcall(require, "nvim-web-devicons")

if not ok then
ok, mini_icons = pcall(require, "mini.icons")
web_devicons = nil
end

if not ok then
config.get_config().use_icons = false
utils.warn(
"nvim-web-devicons is required to use file icons! "
"nvim-web-devicons or mini.icons is required to use file icons! "
.. "Set `use_icons = false` in your config to stop seeing this message."
)

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

if icon_cache[icon_key] then
icon, hl = unpack(icon_cache[icon_key])
else
elseif web_devicons then
icon, hl = web_devicons.get_icon(name, ext, { default = true })
icon_cache[icon_key] = { icon, hl }
else
icon, hl = mini_icons.get("file", name)
icon_cache[icon_key] = { icon, hl }
end

if icon then
Expand Down