Skip to content

Commit

Permalink
feat(#35): support mini.icons as an icon provider
Browse files Browse the repository at this point in the history
  • Loading branch information
prichrd committed Jul 11, 2024
1 parent c64f60b commit d86ff55
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 90 deletions.
85 changes: 34 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,73 +15,56 @@ a layer of *✨bling✨* and configuration to your favorite file explorer.
## Requirements

- Neovim >= 0.5.0
- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons) (optional)
- One of the following icon provider plugin (optional):
- [mini.icons](https://github.com/echasnovski/mini.icons)
- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons)
- [A patched font](https://www.nerdfonts.com/) (optional)

## Installing

Install the plugin with your preferred package manager:

[vim-plug](https://github.com/junegunn/vim-plug)
<details>
<summary><a href="https://github.com/folke/lazy.nvim">lazy.nvim</a></summary>
<code>{ 'prichrd/netrw.nvim', opts = {} }</code>
</details>

```vim
Plug 'prichrd/netrw.nvim'
```
<details>
<summary><a href="https://github.com/junegunn/vim-plug">vim-plug</a></summary>
<code>Plug 'prichrd/netrw.nvim'</code>
</details>

<details>
<summary><a href="https://github.com/wbthomason/packer.nvim">packer</a></summary>
<code>use 'prichrd/netrw.nvim'</code>
</details>

[packer](https://github.com/wbthomason/packer.nvim)
## Configuration

Enable the plugin with the default configuration:
```lua
use 'prichrd/netrw.nvim'
require("netrw").setup({})
```

## Usage

Enable the plugin:

Or customize the options to fit your needs:
```lua
require'netrw'.setup{
-- Put your configuration here, or leave the object empty to take the default
-- configuration.
require("netrw").setup({
-- File icons to use when `use_devicons` is false or if
-- no icon is found for the given file type.
icons = {
symlink = '', -- Symlink icon (directory and file)
directory = '', -- Directory icon
file = '', -- File icon
symlink = '',
directory = '',
file = '',
},
use_devicons = true, -- Uses nvim-web-devicons if true, otherwise use the file icon specified above
mappings = {}, -- Custom key mappings
}
```

Custom key mappings:

```lua
require'netrw'.setup{
-- your config ...

-- Define normal mode mapping
-- Uses mini.icon or nvim-web-devicons if true, otherwise use the file icon specified above
use_devicons = true,
mappings = {
-- Function mappings
['p'] = function(payload)
-- Payload is an object describing the node under the cursor, the object
-- has the following keys:
-- - dir: the current netrw directory (vim.b.netrw_curdir)
-- - node: the name of the file or directory under the cursor
-- - link: the referenced file if the node under the cursor is a symlink
-- - extension: the file extension if the node under the cursor is a file
-- - type: the type of node under the cursor (0 = dir, 1 = file, 2 = symlink)
-- - col: the column of the node (for liststyle 3)
print(vim.inspect(payload))
end,
-- String command mappings
['<Leader><Tab>'] = ":echo 'string command'<CR>",
-- more mappings ...
}
-- your config ...
}
```

The plugin documentation can be found at [doc/netrw.nvim.txt](doc/netrw.nvim.txt).
You can also use the :help netrw.nvim command inside of Neovim.
-- Function mappings receive an object describing the node under the cursor
['p'] = function(payload) print(vim.inspect(payload)) end,
-- String mappings are executed as vim commands
['<Leader>p'] = ":echo 'hello world'<CR>",
},
})

## Contributing

Expand Down
63 changes: 25 additions & 38 deletions doc/netrw.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CONTENTS
*netrw-contents*

1. Intro (|netrw-intro|)
2. Configure (|netrw-configure|)
2. Configuration (|netrw-configuration|)

==============================================================================
INTRO
Expand All @@ -19,49 +19,36 @@ explorer:

It requires Neovim 0.5.0 and other optional dependencies:

* mini.icons
* nvim-web-devicons
* A patched font (see README.md for links to install)

==============================================================================
CONFIGURE
*netrw-configure*

Enable the plugin: >
require'netrw'.setup{
-- Put your configuration here, or leave the object empty to take the default
-- configuration.
CONFIGURATION
*netrw-configuration*

Enable the plugin with the default configuration:
>lua
require("netrw").setup({})

Or customize the options to fit your needs:
>lua
require("netrw").setup({
-- File icons to use when `use_devicons` is false or if
-- no icon is found for the given file type.
icons = {
symlink = '', -- Symlink icon (directory and file)
directory = '', -- Directory icon
file = '', -- File icon
symlink = '',
directory = '',
file = '',
},
use_devicons = true, -- Uses nvim-web-devicons if true, otherwise use the file icon specified above
mappings = {}, -- Custom key mappings
}
Custom key mappings: >
require'netrw'.setup{
-- your config ...
-- Define normal mode mapping
-- Uses mini.icon or nvim-web-devicons if true, otherwise use the file icon specified above
use_devicons = true,
mappings = {
-- Function mappings
['p'] = function(payload)
-- Payload is an object describing the node under the cursor, the object
-- has the following keys:
-- - dir: the current netrw directory (vim.b.netrw_curdir)
-- - node: the name of the file or directory under the cursor
-- - link: the referenced file if the node under the cursor is a symlink
-- - extension: the file extension if the node under the cursor is a file
-- - type: the type of node under the cursor (0 = dir, 1 = file, 2 = symlink)
-- - col: the column of the node (for liststyle 3)
print(vim.inspect(payload))
end,
-- String command mappings
['<Leader><Tab>'] = ":echo 'string command'<CR>",
-- more mappings ...
}
-- your config ...
}
-- Function mappings receive an object describing the node under the cursor
['p'] = function(payload) print(vim.inspect(payload)) end,
-- String mappings are executed as vim commands
['<Leader>p'] = ":echo 'hello world'<CR>",
},
})

vim: ft=help tw=78 et ts=2 sw=2 sts=2 norl
10 changes: 9 additions & 1 deletion lua/netrw/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ local get_icon = function(node)
if node.type == parse.TYPE_FILE then
icon = config.options.icons.file
if config.options.use_devicons then
local has_miniicons, miniicons = pcall(require, "mini.icons")
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
if has_devicons then

if has_miniicons then
local ic, hi = miniicons.get("file", node.node)
if ic then
icon = ic
hl_group = hi
end
elseif has_devicons then
local ic, hi = devicons.get_icon(node.node, nil, { strict = true, default = false })
if ic then
icon = ic
Expand Down

0 comments on commit d86ff55

Please sign in to comment.