Skip to content

feat(#406): add set_icon_by_filetype #407

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

Merged
merged 1 commit into from
Mar 2, 2024
Merged
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ You can override the default icon with the `set_default_icon(icon, color, cterm_
require("nvim-web-devicons").set_default_icon('', '#6d8086', 65)
```

### Getting icons by filetype
### Getting and setting icons by filetype

You can get the icon and colors associated with a filetype using the `by_filetype` functions:

Expand All @@ -177,6 +177,12 @@ require("nvim-web-devicons").get_icon_color_by_filetype(filetype, opts)
require("nvim-web-devicons").get_icon_cterm_color_by_filetype(filetype, opts)
```

or set the icon to use for a filetype with:

```lua
require("nvim-web-devicons").set_icon_by_filetype { cpp = "c", pandoc = "md", }
```

These functions are the same as their counterparts without the `_by_filetype` suffix, but they take a filetype instead of a name/extension.

You can also use `get_icon_name_by_filetype(filetype)` to get the icon name associated with the filetype.
Expand Down
4 changes: 4 additions & 0 deletions lua/nvim-web-devicons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ function M.set_icon(user_icons)
end
end

function M.set_icon_by_filetype(user_filetypes)
filetypes = vim.tbl_extend("force", filetypes, user_filetypes or {})
end

function M.set_default_icon(icon, color, cterm_color)
default_icon.icon = icon
default_icon.color = color
Expand Down