diff --git a/README.md b/README.md index 1973a0e..055fcfe 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ https://user-images.githubusercontent.com/506791/209727111-6b4a11f4-634a-4efa-94 - Neovim 0.10+ - Optional: - [mini.icons](https://github.com/nvim-mini/mini.nvim/blob/main/readmes/mini-icons.md) - or [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) for - file icons + [mini.icons](https://github.com/nvim-mini/mini.nvim/blob/main/readmes/mini-icons.md), + [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons), or + [nonicons.nvim](https://github.com/barrettruth/nonicons.nvim) for file icons ## Installation diff --git a/lua/oil/util.lua b/lua/oil/util.lua index d9bca22..af73d4e 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -965,6 +965,32 @@ M.get_icon_provider = function() end end end + + local has_nonicons, nonicons = pcall(require, 'nonicons') + if has_nonicons and type(nonicons.get) == 'function' then + return function(type, name, conf, ft) + if type == 'directory' then + local icon = nonicons.get('file-directory') + return icon or (conf and conf.directory or ''), 'OilDirIcon' + else + if ft then + local ft_icon = nonicons.get(ft) + if ft_icon then + return ft_icon, 'OilFileIcon' + end + end + local ext = name:match('%.([^%.]+)$') + if ext then + local ext_icon = nonicons.get(ext) + if ext_icon then + return ext_icon, 'OilFileIcon' + end + end + local icon = nonicons.get('file') + return icon or (conf and conf.default_file or ''), 'OilFileIcon' + end + end + end end ---Read a buffer into a scratch buffer and apply syntactic highlighting when possible