Regenerate nvim config
This commit is contained in:
@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
|
||||
[*.lua]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
54
config/neovim/store/lazy-plugins/nvim-web-devicons/.github/workflows/ci.yml
vendored
Normal file
54
config/neovim/store/lazy-plugins/nvim-web-devicons/.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: leafo/gh-actions-lua@v10
|
||||
with:
|
||||
luaVersion: "5.1"
|
||||
|
||||
- uses: leafo/gh-actions-luarocks@v4
|
||||
|
||||
- name: luacheck
|
||||
run: |
|
||||
luarocks install luacheck 1.1.1
|
||||
make lint
|
||||
|
||||
style:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: stylua
|
||||
uses: JohnnyMorganz/stylua-action@v3
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
version: "0.19"
|
||||
args: --check lua scripts
|
||||
|
||||
colors:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: rhysd/action-setup-vim@v1
|
||||
with:
|
||||
neovim: true
|
||||
|
||||
- name: make colors-check
|
||||
run: make colors-check
|
||||
|
||||
23
config/neovim/store/lazy-plugins/nvim-web-devicons/.github/workflows/pre-commit-autoupdate.yml
vendored
Normal file
23
config/neovim/store/lazy-plugins/nvim-web-devicons/.github/workflows/pre-commit-autoupdate.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
name: Pre-commit autoupdate
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
workflow_dispatch:
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
jobs:
|
||||
auto-update:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-python@v4.5.0
|
||||
- run: pip install pre-commit
|
||||
- run: pre-commit autoupdate
|
||||
- uses: peter-evans/create-pull-request@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
branch: update/pre-commit-hooks
|
||||
title: "chore: update pre-commit hooks"
|
||||
commit-message: "chore: update pre-commit hooks"
|
||||
body: Update versions of pre-commit hooks to latest version.
|
||||
28
config/neovim/store/lazy-plugins/nvim-web-devicons/.github/workflows/release.yml
vendored
Normal file
28
config/neovim/store/lazy-plugins/nvim-web-devicons/.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
luarocks-upload:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: LuaRocks Upload
|
||||
uses: nvim-neorocks/luarocks-tag-release@v5
|
||||
env:
|
||||
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
|
||||
with:
|
||||
summary: Nerd Font icons for neovim
|
||||
detailed_description: |
|
||||
Coloured Nerd Font file icons for neovim.
|
||||
|
||||
Dark and light background variants.
|
||||
|
||||
https://www.nerdfonts.com/
|
||||
license: MIT
|
||||
labels: neovim
|
||||
15
config/neovim/store/lazy-plugins/nvim-web-devicons/.github/workflows/semantic-pr-subject.yml
vendored
Normal file
15
config/neovim/store/lazy-plugins/nvim-web-devicons/.github/workflows/semantic-pr-subject.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
name: Semantic Pull Request Subject
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- edited
|
||||
- synchronize
|
||||
jobs:
|
||||
semantic-pr-subject:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: amannn/action-semantic-pull-request@v4.5.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
3
config/neovim/store/lazy-plugins/nvim-web-devicons/.gitignore
vendored
Normal file
3
config/neovim/store/lazy-plugins/nvim-web-devicons/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.lua
|
||||
.luarocks
|
||||
/vim-colortemplate/
|
||||
@ -0,0 +1,7 @@
|
||||
max_line_length = 120
|
||||
|
||||
globals = {
|
||||
"vim",
|
||||
"jit",
|
||||
"bit",
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
|
||||
"runtime.version" : "Lua 5.1",
|
||||
"diagnostics": {
|
||||
"globals": [
|
||||
"vim",
|
||||
"jit",
|
||||
"bit"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
repos:
|
||||
- repo: https://github.com/johnnymorganz/stylua
|
||||
rev: v0.20.0
|
||||
hooks:
|
||||
- id: stylua-github
|
||||
fail_fast: true
|
||||
verbose: true
|
||||
types: [lua]
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: luacheck
|
||||
name: Luacheck
|
||||
description: Lints Lua files using Luacheck.
|
||||
entry: luacheck --
|
||||
language: system
|
||||
fail_fast: true
|
||||
verbose: true
|
||||
types: [lua]
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: colors
|
||||
name: colors
|
||||
description: Ensures Light Color Scheme version has been generated.
|
||||
entry: make colors
|
||||
language: system
|
||||
require_serial: true
|
||||
pass_filenames: false
|
||||
verbose: true
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
column_width = 120
|
||||
line_endings = "Unix"
|
||||
indent_type = "Spaces"
|
||||
indent_width = 2
|
||||
quote_style = "AutoPreferDouble"
|
||||
call_parentheses = "None"
|
||||
@ -0,0 +1,136 @@
|
||||
# Contributing to `nvim-web-devicons`
|
||||
|
||||
Thank you for your contribution!
|
||||
|
||||
## Order
|
||||
|
||||
Please ensure `icons_by_filename`, `icons_by_file_extension` and `filetypes` are ordered alphabetically, to prevent merge conflicts.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Code is formatted using stylua and linted using luacheck.
|
||||
|
||||
You can install these with:
|
||||
```sh
|
||||
cargo install stylua
|
||||
luarocks install luacheck
|
||||
```
|
||||
|
||||
or via your OS package manager e.g. Arch linux:
|
||||
```sh
|
||||
pacman -S stylua
|
||||
pacman -S luacheck
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
Following your changes, please run:
|
||||
|
||||
```sh
|
||||
make
|
||||
```
|
||||
|
||||
This will:
|
||||
1. `git clone --depth 1 https://github.com/lifepillar/vim-colortemplate.git vim-colortemplate` if necessary
|
||||
1. Generate cterm colors
|
||||
2. Generate light color variants
|
||||
3. Check style
|
||||
4. Lint
|
||||
|
||||
You can automatically fix any style issues via:
|
||||
```sh
|
||||
make style-fix
|
||||
```
|
||||
|
||||
## Generate Colors
|
||||
|
||||
Add or update icons in `lua/nvim-web-devicons/icons-default.lua`
|
||||
|
||||
There are two tables where icons can be added:
|
||||
1. icons_by_filename
|
||||
2. icons_by_file_extension
|
||||
|
||||
Add the icon in table 1. if the icon is for a file that is always named that
|
||||
way, for example `.gitconfig`. Add to table 2. if the icon is for all files
|
||||
with an extension.
|
||||
|
||||
Each icon must have the following (this is an example):
|
||||
```lua
|
||||
[".gitconfig"] = {
|
||||
icon = "",
|
||||
color = "#41535b",
|
||||
cterm_color = "0",
|
||||
name = "GitConfig",
|
||||
},
|
||||
```
|
||||
___Key/value pairs must appear in the same exact order!___
|
||||
|
||||
- `color` must contain a color in the html notation
|
||||
- `cterm_color` must be below `color`, and it must contain a number (any number)
|
||||
- the correct value for `cterm_color` will be generated by the script
|
||||
- `name` must only contain alphanumeric characters (don't use `/`, `-`, `_`)
|
||||
|
||||
Ensure your current working directory is the repo root.
|
||||
Run `make`. This will:
|
||||
- Update `cterm_color` based on `color`
|
||||
- Generate `lua/nvim-web-devicons/icons-light.lua`
|
||||
|
||||
Please commit both `lua/nvim-web-devicons/icons-default.lua` and `lua/nvim-web-devicons/icons-light.lua`
|
||||
|
||||
## Test
|
||||
|
||||
Run `:NvimWebDeviconsHiTest` to view the icons and their highlighting.
|
||||
|
||||
Start neovim with `TERM=xterm-256color nvim ...` to test cterm.
|
||||
|
||||
Check with `&background` `dark` and `light`
|
||||
|
||||
## Documentation
|
||||
|
||||
When modifying or adding API, please update [Usage](README.md#Usage)
|
||||
|
||||
# Pull Request
|
||||
|
||||
Please reference any issues in the description e.g. "resolves #1234", which will be closed upon merge.
|
||||
|
||||
Please check "allow edits by maintainers" to allow nvim-web-devicons maintainers to make small changes such as documentation tweaks.
|
||||
|
||||
## Subject
|
||||
|
||||
The merge commit message will be the subject of the PR.
|
||||
|
||||
A [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0) subject will be validated by the Semantic Pull Request Subject CI job. Reference the issue to be used in the release notes e.g.
|
||||
|
||||
```
|
||||
feat: add gradle icons
|
||||
fix: update rust icon
|
||||
feat(#192): :NvimWebDeviconsHiTest
|
||||
```
|
||||
|
||||
Available types:
|
||||
* feat: A new feature
|
||||
* fix: A bug fix
|
||||
* docs: Documentation only changes
|
||||
* style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
||||
* refactor: A code change that neither fixes a bug nor adds a feature
|
||||
* perf: A code change that improves performance
|
||||
* test: Adding missing tests or correcting existing tests
|
||||
* build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
|
||||
* ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
|
||||
* chore: Other changes that don't modify src or test files
|
||||
* revert: Reverts a previous commit
|
||||
|
||||
If in doubt, look at previous commits.
|
||||
|
||||
See also [The Conventional Commits ultimate cheatsheet](https://gist.github.com/gabrielecanepa/fa6cca1a8ae96f77896fe70ddee65527)
|
||||
|
||||
## Browser Font
|
||||
|
||||
It is useful to see the actual glyphs in the pull request. That can be done by setting the browser font to your nerd font.
|
||||
|
||||
Using firefox:
|
||||
|
||||
* Settings -> General
|
||||
* Fonts -> Advanced
|
||||
* Change Monospace to "Hack Nerd Font Mono" or similar
|
||||
* Uncheck "Allow pages to choose their own fonts, instead of your selections above"
|
||||
21
config/neovim/store/lazy-plugins/nvim-web-devicons/LICENSE
Normal file
21
config/neovim/store/lazy-plugins/nvim-web-devicons/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 nvim-tree
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
32
config/neovim/store/lazy-plugins/nvim-web-devicons/Makefile
Normal file
32
config/neovim/store/lazy-plugins/nvim-web-devicons/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
VIM_COLORTEMPLATE_VERSION = 2.2.3
|
||||
|
||||
all: colors style-check lint
|
||||
|
||||
colors: vim-colortemplate
|
||||
nvim \
|
||||
--clean \
|
||||
--headless \
|
||||
--cmd "set rtp^=vim-colortemplate" \
|
||||
-c 'source scripts/generate_colors.lua' \
|
||||
-c 'qall'
|
||||
|
||||
colors-check: colors
|
||||
git diff --exit-code lua/nvim-web-devicons/icons-light.lua
|
||||
|
||||
vim-colortemplate:
|
||||
mkdir -p vim-colortemplate
|
||||
curl -L https://github.com/lifepillar/vim-colortemplate/archive/refs/tags/v$(VIM_COLORTEMPLATE_VERSION).tar.gz | tar zx --directory vim-colortemplate --strip-components=1
|
||||
|
||||
style-check:
|
||||
stylua . --check
|
||||
|
||||
style-fix:
|
||||
stylua .
|
||||
|
||||
lint:
|
||||
luacheck lua scripts
|
||||
|
||||
clean:
|
||||
rm -rf vim-colortemplate
|
||||
|
||||
.PHONY: all colors style-check style-fix lint
|
||||
235
config/neovim/store/lazy-plugins/nvim-web-devicons/README.md
Normal file
235
config/neovim/store/lazy-plugins/nvim-web-devicons/README.md
Normal file
@ -0,0 +1,235 @@
|
||||
# Notice
|
||||
Nerd fonts moved some symbols with version 3.0. Version 2.3 is meant for transition, supporting both version 2 and version 3 icons.
|
||||
|
||||
Nvim-web-devicons requires version 2.3 or above to work properly. If you are unable to update please use your plugin manager to pin version of nvim-web-dev icons to `nerd-v2-compat` tag.
|
||||
|
||||
# Nvim-web-devicons
|
||||
|
||||
A `lua` fork of [vim-devicons](https://github.com/ryanoasis/vim-devicons). This plugin provides the same icons _as well as_ colors for each icon.
|
||||
|
||||
Light and dark color variants are provided.
|
||||
|
||||
## Requirements
|
||||
|
||||
- [neovim >=0.7.0](https://github.com/neovim/neovim/wiki/Installing-Neovim)
|
||||
- [A patched font](https://www.nerdfonts.com/)
|
||||
|
||||
## Installation
|
||||
|
||||
```vim
|
||||
Plug 'nvim-tree/nvim-web-devicons'
|
||||
```
|
||||
|
||||
or with [packer.nvim](https://github.com/wbthomason/packer.nvim)
|
||||
|
||||
```
|
||||
use 'nvim-tree/nvim-web-devicons'
|
||||
```
|
||||
|
||||
[](https://luarocks.org/modules/nvim-tree/nvim-web-devicons)
|
||||
|
||||
## Usage
|
||||
|
||||
### Viewing
|
||||
|
||||
Run `:NvimWebDeviconsHiTest` to see all icons and their highlighting.
|
||||
|
||||
### Variants
|
||||
|
||||
Light or dark color variants of the icons depend on `&background`.
|
||||
|
||||
The variant is updated:
|
||||
- on `OptionSet` event for `background`, or
|
||||
- after explicitly calling `require("nvim-web-devicons").refresh()`.
|
||||
|
||||
However, be advised that the plugin using nvim-web-devicons may have cached the icons.
|
||||
|
||||
### Setup
|
||||
|
||||
This adds all the highlight groups for the devicons
|
||||
i.e. it calls `vim.api.nvim_set_hl` for all icons
|
||||
this might need to be re-called in a `Colorscheme` to re-apply cleared highlights
|
||||
if the color scheme changes
|
||||
|
||||
```lua
|
||||
require'nvim-web-devicons'.setup {
|
||||
-- your personnal icons can go here (to override)
|
||||
-- you can specify color or cterm_color instead of specifying both of them
|
||||
-- DevIcon will be appended to `name`
|
||||
override = {
|
||||
zsh = {
|
||||
icon = "",
|
||||
color = "#428850",
|
||||
cterm_color = "65",
|
||||
name = "Zsh"
|
||||
}
|
||||
};
|
||||
-- globally enable different highlight colors per icon (default to true)
|
||||
-- if set to false all icons will have the default icon's color
|
||||
color_icons = true;
|
||||
-- globally enable default icons (default to false)
|
||||
-- will get overriden by `get_icons` option
|
||||
default = true;
|
||||
-- globally enable "strict" selection of icons - icon will be looked up in
|
||||
-- different tables, first by filename, and if not found by extension; this
|
||||
-- prevents cases when file doesn't have any extension but still gets some icon
|
||||
-- because its name happened to match some extension (default to false)
|
||||
strict = true;
|
||||
-- same as `override` but specifically for overrides by filename
|
||||
-- takes effect when `strict` is true
|
||||
override_by_filename = {
|
||||
[".gitignore"] = {
|
||||
icon = "",
|
||||
color = "#f1502f",
|
||||
name = "Gitignore"
|
||||
}
|
||||
};
|
||||
-- same as `override` but specifically for overrides by extension
|
||||
-- takes effect when `strict` is true
|
||||
override_by_extension = {
|
||||
["log"] = {
|
||||
icon = "",
|
||||
color = "#81e043",
|
||||
name = "Log"
|
||||
}
|
||||
};
|
||||
-- same as `override` but specifically for operating system
|
||||
-- takes effect when `strict` is true
|
||||
override_by_operating_system = {
|
||||
["apple"] = {
|
||||
icon = "",
|
||||
color = "#A2AAAD",
|
||||
cterm_color = "248",
|
||||
name = "Apple",
|
||||
},
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Get Icon
|
||||
|
||||
Get the icon for a given file by passing in the `name`, the `extension` and an _optional_ options `table`.
|
||||
The name is passed in to check for an exact match e.g. `.bashrc` if there is no exact name match the extension
|
||||
is used. Calls `.setup()` if it hasn't already ran.
|
||||
|
||||
```lua
|
||||
require'nvim-web-devicons'.get_icon(filename, extension, options)
|
||||
```
|
||||
|
||||
The optional `options` argument can used to change how the plugin works the keys include
|
||||
`default = <boolean>` and `strict = <boolean>`. If the default key is set to true this
|
||||
function will return a default if there is no matching icon. If the strict key is set
|
||||
to true this function will lookup icon specifically by filename, and if not found then
|
||||
specifically by extension, and fallback to default icon if default key is set to true.
|
||||
e.g.
|
||||
|
||||
```lua
|
||||
require'nvim-web-devicons'.get_icon(filename, extension, { default = true })
|
||||
```
|
||||
|
||||
You can check if the setup function was already called with:
|
||||
```lua
|
||||
require'nvim-web-devicons'.has_loaded()
|
||||
```
|
||||
|
||||
### Get icon and color code
|
||||
|
||||
`get_icon_color` differs from `get_icon` only in the second return value.
|
||||
`get_icon_cterm_color` returns cterm color instead of gui color
|
||||
`get_icon` returns icon and highlight name.
|
||||
If you want to get color code, you can use this function.
|
||||
```lua
|
||||
local icon, color = require'nvim-web-devicons'.get_icon_color("init.lua", "lua")
|
||||
assert(icon == "")
|
||||
assert(color == "#51a0cf")
|
||||
```
|
||||
|
||||
### Get all icons
|
||||
|
||||
It is possible to get all of the registered icons with the `get_icons()` function:
|
||||
|
||||
```lua
|
||||
require'nvim-web-devicons'.get_icons()
|
||||
```
|
||||
|
||||
This can be useful for debugging purposes or for creating custom highlights for each icon.
|
||||
|
||||
Mapped categories can be fetched via:
|
||||
|
||||
```lua
|
||||
require'nvim-web-devicons'.get_icons_by_filename()
|
||||
require'nvim-web-devicons'.get_icons_by_extension()
|
||||
require'nvim-web-devicons'.get_icons_by_operating_system()
|
||||
require'nvim-web-devicons'.get_icons_by_desktop_environment()
|
||||
require'nvim-web-devicons'.get_icons_by_window_manager()
|
||||
```
|
||||
|
||||
### Set an icon
|
||||
|
||||
You can override individual icons with the `set_icon({...})` function:
|
||||
|
||||
```lua
|
||||
require("nvim-web-devicons").set_icon {
|
||||
zsh = {
|
||||
icon = "",
|
||||
color = "#428850",
|
||||
cterm_color = "65",
|
||||
name = "Zsh"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can override the default icon with the `set_default_icon(icon, color, cterm_color)` function:
|
||||
|
||||
```lua
|
||||
require("nvim-web-devicons").set_default_icon('', '#6d8086', 65)
|
||||
```
|
||||
|
||||
### Getting and setting icons by filetype
|
||||
|
||||
You can get the icon and colors associated with a filetype using the `by_filetype` functions:
|
||||
|
||||
```lua
|
||||
require("nvim-web-devicons").get_icon_by_filetype(filetype, opts)
|
||||
require("nvim-web-devicons").get_icon_colors_by_filetype(filetype, opts)
|
||||
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.
|
||||
|
||||
## Known Issues
|
||||
|
||||
### My `setup` Overrides Are Not Applied
|
||||
|
||||
*Cause:* A plugin may be calling nvim-web-devicons `setup` before you do. Your `setup` call will be ignored.
|
||||
|
||||
*Workaround:* Call nvim-web-devicons `setup` before the plugin's own `setup`.
|
||||
|
||||
### Windows and WSL not rendering icons properly on some terminals
|
||||
|
||||
On Windows and WSL, it is possible that the icons are not rendered properly when
|
||||
using a terminal that relies on Windows' default system libraries. An example
|
||||
of this is Alacritty ([#271](https://github.com/nvim-tree/nvim-web-devicons/issues/271#issuecomment-2081280928)).
|
||||
Other terminals (e.g. Windows Terminal, and WezTerm) do no have this issue, as
|
||||
they ship newer versions of these libraries. More precisely, they use newer
|
||||
versions of `conpty.dll` and `OpenConsole.exe`. So, as a workaround to the
|
||||
rendering issue, you need to make your terminal use these newer files. Whether
|
||||
this is possible depends on the terminal you are using. Please refer to the
|
||||
terminal's documentation for this.
|
||||
|
||||
In the specific case of Alacritty, you need to place up-to-date `conpty.dll` and
|
||||
`OpenConsole.exe` files in your `PATH`. Microsoft does not provide these files
|
||||
directly, but you can get them from other terminal emulators that ship them.
|
||||
|
||||
## Contributing
|
||||
|
||||
PRs are always welcome! Please see [CONTRIBUTING](CONTRIBUTING.md)
|
||||
@ -0,0 +1,594 @@
|
||||
local M = {}
|
||||
|
||||
-- NOTE: When adding new icons, remember to add an entry to the `filetypes` table, if applicable.
|
||||
local icons, icons_by_filename, icons_by_file_extension, icons_by_operating_system
|
||||
local icons_by_desktop_environment, icons_by_window_manager
|
||||
|
||||
local default_icon = {
|
||||
icon = "",
|
||||
color = "#6d8086",
|
||||
cterm_color = "66",
|
||||
name = "Default",
|
||||
}
|
||||
|
||||
function M.get_icons()
|
||||
return icons
|
||||
end
|
||||
|
||||
function M.get_icons_by_filename()
|
||||
return icons_by_filename
|
||||
end
|
||||
|
||||
function M.get_icons_by_extension()
|
||||
return icons_by_file_extension
|
||||
end
|
||||
|
||||
function M.get_icons_by_operating_system()
|
||||
return icons_by_operating_system
|
||||
end
|
||||
|
||||
function M.get_icons_by_desktop_environment()
|
||||
return icons_by_desktop_environment
|
||||
end
|
||||
|
||||
function M.get_icons_by_window_manager()
|
||||
return icons_by_window_manager
|
||||
end
|
||||
|
||||
local global_opts = {
|
||||
override = {},
|
||||
strict = false,
|
||||
default = false,
|
||||
color_icons = true,
|
||||
}
|
||||
|
||||
-- Set the current icons tables, depending on the 'background' option.
|
||||
local function refresh_icons()
|
||||
local theme
|
||||
if vim.o.background == "light" then
|
||||
theme = require "nvim-web-devicons.icons-light"
|
||||
else
|
||||
theme = require "nvim-web-devicons.icons-default"
|
||||
end
|
||||
|
||||
icons_by_filename = theme.icons_by_filename
|
||||
icons_by_file_extension = theme.icons_by_file_extension
|
||||
icons_by_operating_system = theme.icons_by_operating_system
|
||||
icons_by_desktop_environment = theme.icons_by_desktop_environment
|
||||
icons_by_window_manager = theme.icons_by_window_manager
|
||||
icons = vim.tbl_extend(
|
||||
"keep",
|
||||
{},
|
||||
icons_by_filename,
|
||||
icons_by_file_extension,
|
||||
icons_by_operating_system,
|
||||
icons_by_desktop_environment,
|
||||
icons_by_window_manager
|
||||
)
|
||||
icons = vim.tbl_extend("force", icons, global_opts.override)
|
||||
icons[1] = default_icon
|
||||
end
|
||||
|
||||
-- Map of filetypes -> icon names
|
||||
local filetypes = {
|
||||
["avif"] = "avif",
|
||||
["bash"] = "bash",
|
||||
["bib"] = "bib",
|
||||
["bicep"] = "bicep",
|
||||
["bicepparam"] = "bicepparam",
|
||||
["bzl"] = "bzl",
|
||||
["brewfile"] = "brewfile",
|
||||
["blueprint"] = "blp",
|
||||
["checkhealth"] = "checkhealth",
|
||||
["commit"] = "commit_editmsg",
|
||||
["copying"] = "copying",
|
||||
["gemfile"] = "gemfile$",
|
||||
["lesser"] = "copying.lesser",
|
||||
["vagrantfile"] = "vagrantfile$",
|
||||
["awk"] = "awk",
|
||||
["bmp"] = "bmp",
|
||||
["c"] = "c",
|
||||
["cfg"] = "cfg",
|
||||
["clojure"] = "clj",
|
||||
["cmake"] = "cmake",
|
||||
["cobol"] = "cobol",
|
||||
["coffee"] = "coffee",
|
||||
["conf"] = "conf",
|
||||
["cp"] = "cp",
|
||||
["cpp"] = "cpp",
|
||||
["cr"] = "cr",
|
||||
["cs"] = "cs",
|
||||
["csh"] = "csh",
|
||||
["cson"] = "cson",
|
||||
["css"] = "css",
|
||||
["csv"] = "csv",
|
||||
["cuda"] = "cu",
|
||||
["d"] = "d",
|
||||
["dart"] = "dart",
|
||||
["desktop"] = "desktop",
|
||||
["diff"] = "diff",
|
||||
["doc"] = "doc",
|
||||
["docx"] = "docx",
|
||||
["dockerfile"] = "dockerfile",
|
||||
["dosbatch"] = "bat",
|
||||
["dosini"] = "ini",
|
||||
["dot"] = "dot",
|
||||
["drools"] = "drl",
|
||||
["dropbox"] = "dropbox",
|
||||
["dump"] = "dump",
|
||||
["eex"] = "eex",
|
||||
["ejs"] = "ejs",
|
||||
["elixir"] = "ex",
|
||||
["elm"] = "elm",
|
||||
["epuppet"] = "epp",
|
||||
["erlang"] = "erl",
|
||||
["eruby"] = "erb",
|
||||
["fennel"] = "fnl",
|
||||
["fish"] = "fish",
|
||||
["forth"] = "fs",
|
||||
["fortran"] = "f90",
|
||||
["fsharp"] = "f#",
|
||||
["fsi"] = "fsi",
|
||||
["fsscript"] = "fsscript",
|
||||
["fsx"] = "fsx",
|
||||
["gd"] = "gd",
|
||||
["gif"] = "gif",
|
||||
["git"] = "git",
|
||||
["gitconfig"] = ".gitconfig",
|
||||
["gitcommit"] = "commit_editmsg",
|
||||
["gitignore"] = ".gitignore",
|
||||
["gitattributes"] = ".gitattributes",
|
||||
["glb"] = "glb",
|
||||
["go"] = "go",
|
||||
["godot"] = "godot",
|
||||
["graphql"] = "graphql",
|
||||
["groovy"] = "groovy",
|
||||
["gql"] = "gql",
|
||||
["gruntfile"] = "gruntfile",
|
||||
["gtkrc"] = "gtkrc",
|
||||
["gulpfile"] = "gulpfile",
|
||||
["haml"] = "haml",
|
||||
["haxe"] = "hx",
|
||||
["haskell"] = "hs",
|
||||
["hbs"] = "hbs",
|
||||
["heex"] = "heex",
|
||||
["hex"] = "hex",
|
||||
["html"] = "html",
|
||||
["ico"] = "ico",
|
||||
["idlang"] = "pro",
|
||||
["ino"] = "ino",
|
||||
["import"] = "import",
|
||||
["ipynb"] = "ipynb",
|
||||
["java"] = "java",
|
||||
["javascript"] = "js",
|
||||
["javascript.jsx"] = "jsx",
|
||||
["javascriptreact"] = "jsx",
|
||||
["jpeg"] = "jpeg",
|
||||
["jpg"] = "jpg",
|
||||
["json"] = "json",
|
||||
["jsonc"] = "jsonc",
|
||||
["json5"] = "json5",
|
||||
["julia"] = "jl",
|
||||
["kotlin"] = "kt",
|
||||
["leex"] = "leex",
|
||||
["less"] = "less",
|
||||
["liquid"] = "liquid",
|
||||
["lhaskell"] = "lhs",
|
||||
["license"] = "license",
|
||||
["unlicense"] = "unlicense",
|
||||
["log"] = "log",
|
||||
["lock"] = "lock",
|
||||
["lprolog"] = "sig",
|
||||
["lua"] = "lua",
|
||||
["make"] = "makefile",
|
||||
["markdown"] = "markdown",
|
||||
["material"] = "material",
|
||||
["mdx"] = "mdx",
|
||||
["mint"] = "mint",
|
||||
["motoko"] = "mo",
|
||||
["mustache"] = "mustache",
|
||||
["nim"] = "nim",
|
||||
["nix"] = "nix",
|
||||
["nu"] = "nu",
|
||||
["node"] = "node_modules",
|
||||
["obj"] = "obj",
|
||||
["ocaml"] = "ml",
|
||||
["openscad"] = "scad",
|
||||
["opus"] = "opus",
|
||||
["otf"] = "otf",
|
||||
["pck"] = "pck",
|
||||
["pdf"] = "pdf",
|
||||
["perl"] = "pl",
|
||||
["php"] = "php",
|
||||
["plaintex"] = "tex",
|
||||
["png"] = "png",
|
||||
["po"] = "po",
|
||||
["postscr"] = "ai",
|
||||
["ppt"] = "ppt",
|
||||
["prisma"] = "prisma",
|
||||
["procfile"] = "procfile",
|
||||
["prolog"] = "pro",
|
||||
["ps1"] = "ps1",
|
||||
["psd1"] = "psd1",
|
||||
["psm1"] = "psm1",
|
||||
["psb"] = "psb",
|
||||
["psd"] = "psd",
|
||||
["puppet"] = "pp",
|
||||
["pyc"] = "pyc",
|
||||
["pyd"] = "pyd",
|
||||
["pyo"] = "pyo",
|
||||
["python"] = "py",
|
||||
["query"] = "query",
|
||||
["r"] = "r",
|
||||
["res"] = "rescript",
|
||||
["resi"] = "rescript",
|
||||
["rlib"] = "rlib",
|
||||
["rmd"] = "rmd",
|
||||
["rproj"] = "rproj",
|
||||
["ruby"] = "rb",
|
||||
["rust"] = "rs",
|
||||
["sass"] = "sass",
|
||||
["sbt"] = "sbt",
|
||||
["scala"] = "scala",
|
||||
["scheme"] = "scm",
|
||||
["scss"] = "scss",
|
||||
["sh"] = "sh",
|
||||
["slim"] = "slim",
|
||||
["sln"] = "sln",
|
||||
["sml"] = "sml",
|
||||
["solidity"] = "sol",
|
||||
["sql"] = "sql",
|
||||
["sqlite"] = "sqlite",
|
||||
["sqlite3"] = "sqlite3",
|
||||
["srt"] = "srt",
|
||||
["ssa"] = "ssa",
|
||||
["styl"] = "styl",
|
||||
["sublime"] = "sublime",
|
||||
["suo"] = "suo",
|
||||
["svelte"] = "svelte",
|
||||
["svg"] = "svg",
|
||||
["swift"] = "swift",
|
||||
["systemverilog"] = "sv",
|
||||
["tads"] = "t",
|
||||
["tcl"] = "tcl",
|
||||
["templ"] = "templ",
|
||||
["terminal"] = "terminal",
|
||||
["tex"] = "tex",
|
||||
["toml"] = "toml",
|
||||
["tres"] = "tres",
|
||||
["tscn"] = "tscn",
|
||||
["twig"] = "twig",
|
||||
["txt"] = "txt",
|
||||
["typescript"] = "ts",
|
||||
["typescriptreact"] = "tsx",
|
||||
["vala"] = "vala",
|
||||
["verilog"] = "v",
|
||||
["vhdl"] = "vhd",
|
||||
["vim"] = "vim",
|
||||
["vue"] = "vue",
|
||||
["wasm"] = "wasm",
|
||||
["webm"] = "webm",
|
||||
["webp"] = "webp",
|
||||
["webpack"] = "webpack",
|
||||
["xcplayground"] = "xcplayground",
|
||||
["xls"] = "xls",
|
||||
["xlsx"] = "xlsx",
|
||||
["xml"] = "xml",
|
||||
["yaml"] = "yaml",
|
||||
["zig"] = "zig",
|
||||
["zsh"] = "zsh",
|
||||
}
|
||||
|
||||
local function get_highlight_name(data)
|
||||
if not global_opts.color_icons then
|
||||
data = default_icon
|
||||
end
|
||||
|
||||
return data.name and "DevIcon" .. data.name
|
||||
end
|
||||
|
||||
local nvim_set_hl = vim.api.nvim_set_hl
|
||||
local function set_up_highlight(icon_data)
|
||||
if not global_opts.color_icons then
|
||||
icon_data = default_icon
|
||||
end
|
||||
|
||||
local hl_group = get_highlight_name(icon_data)
|
||||
if hl_group and (icon_data.color or icon_data.cterm_color) then
|
||||
nvim_set_hl(0, get_highlight_name(icon_data), {
|
||||
fg = icon_data.color,
|
||||
ctermfg = tonumber(icon_data.cterm_color),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local nvim_get_hl_by_name = vim.api.nvim_get_hl_by_name
|
||||
local function highlight_exists(group)
|
||||
if not group then
|
||||
return
|
||||
end
|
||||
|
||||
local ok, hl = pcall(nvim_get_hl_by_name, group, true)
|
||||
return ok and not (hl or {})[true]
|
||||
end
|
||||
|
||||
function M.set_up_highlights(allow_override)
|
||||
if not global_opts.color_icons then
|
||||
set_up_highlight(default_icon)
|
||||
return
|
||||
end
|
||||
|
||||
for _, icon_data in pairs(icons) do
|
||||
local has_color = icon_data.color or icon_data.cterm_color
|
||||
local name_valid = icon_data.name
|
||||
local defined_before = highlight_exists(get_highlight_name(icon_data))
|
||||
if has_color and name_valid and (allow_override or not defined_before) then
|
||||
set_up_highlight(icon_data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function get_highlight_foreground(icon_data)
|
||||
if not global_opts.color_icons then
|
||||
icon_data = default_icon
|
||||
end
|
||||
|
||||
return string.format("#%06x", nvim_get_hl_by_name(get_highlight_name(icon_data), true).foreground)
|
||||
end
|
||||
|
||||
local function get_highlight_ctermfg(icon_data)
|
||||
if not global_opts.color_icons then
|
||||
icon_data = default_icon
|
||||
end
|
||||
|
||||
return nvim_get_hl_by_name(get_highlight_name(icon_data), false).foreground
|
||||
end
|
||||
|
||||
local loaded = false
|
||||
|
||||
function M.has_loaded()
|
||||
return loaded
|
||||
end
|
||||
|
||||
local if_nil = vim.F.if_nil
|
||||
function M.setup(opts)
|
||||
if loaded then
|
||||
return
|
||||
end
|
||||
|
||||
loaded = true
|
||||
|
||||
local user_icons = opts or {}
|
||||
|
||||
if user_icons.default then
|
||||
global_opts.default = true
|
||||
end
|
||||
|
||||
if user_icons.strict then
|
||||
global_opts.strict = true
|
||||
end
|
||||
|
||||
global_opts.color_icons = if_nil(user_icons.color_icons, global_opts.color_icons)
|
||||
|
||||
if user_icons.override and user_icons.override.default_icon then
|
||||
default_icon = user_icons.override.default_icon
|
||||
end
|
||||
|
||||
local user_filename_icons = user_icons.override_by_filename
|
||||
local user_file_ext_icons = user_icons.override_by_extension
|
||||
local user_operating_system_icons = user_icons.override_by_operating_system
|
||||
local user_desktop_environment_icons = user_icons.override_by_desktop_environment
|
||||
local user_window_manager_icons = user_icons.override_by_window_manager
|
||||
|
||||
icons = vim.tbl_extend(
|
||||
"force",
|
||||
icons,
|
||||
user_icons.override or {},
|
||||
user_filename_icons or {},
|
||||
user_file_ext_icons or {},
|
||||
user_operating_system_icons or {},
|
||||
user_desktop_environment_icons or {},
|
||||
user_window_manager_icons or {}
|
||||
)
|
||||
global_opts.override = vim.tbl_extend(
|
||||
"force",
|
||||
global_opts.override,
|
||||
user_icons.override or {},
|
||||
user_filename_icons or {},
|
||||
user_file_ext_icons or {},
|
||||
user_operating_system_icons or {},
|
||||
user_desktop_environment_icons or {},
|
||||
user_window_manager_icons or {}
|
||||
)
|
||||
|
||||
if user_filename_icons then
|
||||
icons_by_filename = vim.tbl_extend("force", icons_by_filename, user_filename_icons)
|
||||
end
|
||||
if user_file_ext_icons then
|
||||
icons_by_file_extension = vim.tbl_extend("force", icons_by_file_extension, user_file_ext_icons)
|
||||
end
|
||||
if user_operating_system_icons then
|
||||
icons_by_operating_system = vim.tbl_extend("force", icons_by_operating_system, user_operating_system_icons)
|
||||
end
|
||||
if user_desktop_environment_icons then
|
||||
icons_by_desktop_environment = vim.tbl_extend("force", icons_by_desktop_environment, user_desktop_environment_icons)
|
||||
end
|
||||
if user_window_manager_icons then
|
||||
icons_by_window_manager = vim.tbl_extend("force", icons_by_window_manager, user_window_manager_icons)
|
||||
end
|
||||
|
||||
icons[1] = default_icon
|
||||
|
||||
M.set_up_highlights()
|
||||
|
||||
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||
desc = "Re-apply icon colors after changing colorschemes",
|
||||
group = vim.api.nvim_create_augroup("NvimWebDevicons", { clear = true }),
|
||||
callback = M.set_up_highlights,
|
||||
})
|
||||
|
||||
-- highlight test command
|
||||
vim.api.nvim_create_user_command("NvimWebDeviconsHiTest", function()
|
||||
require "nvim-web-devicons.hi-test"(
|
||||
default_icon,
|
||||
global_opts.override,
|
||||
icons_by_filename,
|
||||
icons_by_file_extension,
|
||||
icons_by_operating_system,
|
||||
icons_by_desktop_environment,
|
||||
icons_by_window_manager
|
||||
)
|
||||
end, {
|
||||
desc = "nvim-web-devicons: highlight test",
|
||||
})
|
||||
end
|
||||
|
||||
function M.get_default_icon()
|
||||
return default_icon
|
||||
end
|
||||
|
||||
-- recursively iterate over each segment separated by '.' to parse extension with multiple dots in filename
|
||||
local function iterate_multi_dotted_extension(name, icon_table)
|
||||
if name == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local compound_ext = name:match "%.(.*)"
|
||||
local icon = icon_table[compound_ext]
|
||||
if icon then
|
||||
return icon
|
||||
end
|
||||
|
||||
return iterate_multi_dotted_extension(compound_ext, icon_table)
|
||||
end
|
||||
|
||||
local function get_icon_by_extension(name, ext, opts)
|
||||
local is_strict = if_nil(opts and opts.strict, global_opts.strict)
|
||||
local icon_table = is_strict and icons_by_file_extension or icons
|
||||
|
||||
if ext ~= nil then
|
||||
return icon_table[ext]
|
||||
end
|
||||
|
||||
return iterate_multi_dotted_extension(name, icon_table)
|
||||
end
|
||||
|
||||
local function get_icon_data(name, ext, opts)
|
||||
if type(name) == "string" then
|
||||
name = name:lower()
|
||||
end
|
||||
|
||||
if not loaded then
|
||||
M.setup()
|
||||
end
|
||||
|
||||
local has_default = if_nil(opts and opts.default, global_opts.default)
|
||||
local is_strict = if_nil(opts and opts.strict, global_opts.strict)
|
||||
local icon_data
|
||||
if is_strict then
|
||||
icon_data = icons_by_filename[name] or get_icon_by_extension(name, ext, opts) or (has_default and default_icon)
|
||||
else
|
||||
icon_data = icons[name] or get_icon_by_extension(name, ext, opts) or (has_default and default_icon)
|
||||
end
|
||||
|
||||
return icon_data
|
||||
end
|
||||
|
||||
function M.get_icon(name, ext, opts)
|
||||
local icon_data = get_icon_data(name, ext, opts)
|
||||
|
||||
if icon_data then
|
||||
return icon_data.icon, get_highlight_name(icon_data)
|
||||
end
|
||||
end
|
||||
|
||||
function M.get_icon_name_by_filetype(ft)
|
||||
return filetypes[ft]
|
||||
end
|
||||
|
||||
function M.get_icon_by_filetype(ft, opts)
|
||||
local name = M.get_icon_name_by_filetype(ft)
|
||||
opts = opts or {}
|
||||
opts.strict = false
|
||||
return M.get_icon(name or "", nil, opts)
|
||||
end
|
||||
|
||||
function M.get_icon_colors(name, ext, opts)
|
||||
local icon_data = get_icon_data(name, ext, opts)
|
||||
|
||||
if icon_data then
|
||||
local color = icon_data.color
|
||||
local cterm_color = icon_data.cterm_color
|
||||
if icon_data.name and highlight_exists(get_highlight_name(icon_data)) then
|
||||
color = get_highlight_foreground(icon_data) or color
|
||||
cterm_color = get_highlight_ctermfg(icon_data) or cterm_color
|
||||
end
|
||||
return icon_data.icon, color, cterm_color
|
||||
end
|
||||
end
|
||||
|
||||
function M.get_icon_colors_by_filetype(ft, opts)
|
||||
local name = M.get_icon_name_by_filetype(ft)
|
||||
return M.get_icon_colors(name or "", nil, opts)
|
||||
end
|
||||
|
||||
function M.get_icon_color(name, ext, opts)
|
||||
local data = { M.get_icon_colors(name, ext, opts) }
|
||||
return data[1], data[2]
|
||||
end
|
||||
|
||||
function M.get_icon_color_by_filetype(ft, opts)
|
||||
local name = M.get_icon_name_by_filetype(ft)
|
||||
opts = opts or {}
|
||||
opts.strict = false
|
||||
return M.get_icon_color(name or "", nil, opts)
|
||||
end
|
||||
|
||||
function M.get_icon_cterm_color(name, ext, opts)
|
||||
local data = { M.get_icon_colors(name, ext, opts) }
|
||||
return data[1], data[3]
|
||||
end
|
||||
|
||||
function M.get_icon_cterm_color_by_filetype(ft, opts)
|
||||
local name = M.get_icon_name_by_filetype(ft)
|
||||
return M.get_icon_cterm_color(name or "", nil, opts)
|
||||
end
|
||||
|
||||
function M.set_icon(user_icons)
|
||||
icons = vim.tbl_extend("force", icons, user_icons or {})
|
||||
global_opts.override = vim.tbl_extend("force", global_opts.override, user_icons or {})
|
||||
if not global_opts.color_icons then
|
||||
return
|
||||
end
|
||||
|
||||
for _, icon_data in pairs(user_icons) do
|
||||
set_up_highlight(icon_data)
|
||||
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
|
||||
default_icon.cterm_color = cterm_color
|
||||
set_up_highlight(default_icon)
|
||||
end
|
||||
|
||||
-- Load the icons already, the loaded tables depend on the 'background' setting.
|
||||
refresh_icons()
|
||||
|
||||
function M.refresh()
|
||||
refresh_icons()
|
||||
M.set_up_highlights(true)
|
||||
end
|
||||
|
||||
-- Change icon set on background change
|
||||
vim.api.nvim_create_autocmd("OptionSet", {
|
||||
pattern = "background",
|
||||
callback = M.refresh,
|
||||
})
|
||||
|
||||
return M
|
||||
@ -0,0 +1,136 @@
|
||||
---Run a test similar to :so $VIMRUNTIME/syntax/hitest.vim
|
||||
---Display all icons and their group highlighted, followed by the concrete definition
|
||||
--
|
||||
---@class IconDisplay for :NvimTreeHiTest
|
||||
---@field tag string filename, os or extension
|
||||
---@field name string name without prefix
|
||||
---@field icon string icon itself
|
||||
---@field group string|nil :hi group name
|
||||
---@field def string|nil :hi concrete definition
|
||||
local IconDisplay = {}
|
||||
|
||||
---@param o IconDisplay
|
||||
---@return IconDisplay|nil
|
||||
function IconDisplay:new(o)
|
||||
if type(o.tag) ~= "string" or type(o.name) ~= "string" or type(o.icon) ~= "string" then
|
||||
return nil
|
||||
end
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
o.group = "DevIcon" .. o.name
|
||||
o.tag = o.tag or ""
|
||||
|
||||
-- concrete definition
|
||||
local ok, res = pcall(vim.api.nvim_cmd, { cmd = "highlight", args = { o.group } }, { output = true })
|
||||
if ok and type(res) == "string" then
|
||||
o.def = res:gsub(".*xxx *", "")
|
||||
else
|
||||
o.def = ""
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Write the line with highlighting
|
||||
---@param bufnr number buffer number
|
||||
---@param max_tag_len number longest tag length
|
||||
---@param max_group_len number longest group length
|
||||
---@param l number line number
|
||||
---@return number l incremented
|
||||
function IconDisplay:render(bufnr, max_tag_len, max_group_len, l)
|
||||
local fmt = string.format("%%s %%-%d.%ds %%-%d.%ds %%s", max_tag_len, max_tag_len, max_group_len, max_group_len)
|
||||
local text = string.format(fmt, self.icon, self.tag, self.group, self.def)
|
||||
|
||||
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
||||
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, -1)
|
||||
|
||||
return l + 1
|
||||
end
|
||||
|
||||
---Render a single line of text
|
||||
---@param bufnr number
|
||||
---@param l number line number
|
||||
---@return number l incremented
|
||||
local function render_line(bufnr, l, text)
|
||||
vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
|
||||
return l + 1
|
||||
end
|
||||
|
||||
---Render all icons sorted by tag
|
||||
---@param bufnr number
|
||||
---@param l number line number
|
||||
---@param icons table
|
||||
---@param header string
|
||||
---@return number l incremented
|
||||
local function render_icons(bufnr, l, icons, header)
|
||||
local max_tag_len = 0
|
||||
local max_group_len = 0
|
||||
|
||||
local displays = {}
|
||||
---@cast displays IconDisplay[]
|
||||
|
||||
-- build all icon displays
|
||||
for tag, icon in pairs(icons) do
|
||||
local display = IconDisplay:new { tag = tag, name = icon.name, icon = icon.icon }
|
||||
if display then
|
||||
table.insert(displays, display)
|
||||
max_tag_len = math.max(max_tag_len, #display.tag)
|
||||
max_group_len = math.max(max_group_len, #display.group)
|
||||
end
|
||||
end
|
||||
|
||||
-- sort by name
|
||||
table.sort(displays, function(a, b)
|
||||
return a.name < b.name
|
||||
end)
|
||||
|
||||
l = render_line(bufnr, l, header)
|
||||
l = render_line(bufnr, l, header:gsub(".", "-"))
|
||||
for _, display in ipairs(displays) do
|
||||
l = display:render(bufnr, max_tag_len, max_group_len, l)
|
||||
end
|
||||
l = render_line(bufnr, l, "")
|
||||
|
||||
return l
|
||||
end
|
||||
|
||||
---Create a buffer similar to :ru syntax/hitest.vim displaying each set icons
|
||||
---Icon, name, <tag>, concrete highlight definition
|
||||
---tag and header follows param
|
||||
---@param default_icon table no tag "Default"
|
||||
---@param global_override table[] all global overrides "Overrides"
|
||||
---@param icons_by_filename table[] filename "By File Name"
|
||||
---@param icons_by_file_extension table[] extension "By File Extension"
|
||||
---@param icons_by_operating_system table[] os "By Operating System"
|
||||
---@param icons_by_desktop_environment table[] os "By Desktop Environment"
|
||||
---@param icons_by_window_manager table[] os "By Window Manager"
|
||||
return function(
|
||||
default_icon,
|
||||
global_override,
|
||||
icons_by_filename,
|
||||
icons_by_file_extension,
|
||||
icons_by_operating_system,
|
||||
icons_by_desktop_environment,
|
||||
icons_by_window_manager
|
||||
)
|
||||
-- create a buffer
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
|
||||
-- render and highlight each section
|
||||
local l = 0
|
||||
l = render_icons(bufnr, l, { [""] = default_icon }, "Default")
|
||||
if global_override and next(global_override) then
|
||||
l = render_icons(bufnr, l, global_override, "Overrides")
|
||||
end
|
||||
l = render_icons(bufnr, l, icons_by_filename, "By File Name")
|
||||
l = render_icons(bufnr, l, icons_by_file_extension, "By File Extension")
|
||||
l = render_icons(bufnr, l, icons_by_operating_system, "By Operating System")
|
||||
l = render_icons(bufnr, l, icons_by_desktop_environment, "By Desktop Environment")
|
||||
render_icons(bufnr, l, icons_by_window_manager, "By Window Manager")
|
||||
|
||||
-- finalise and focus the buffer
|
||||
vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
|
||||
vim.cmd.buffer(bufnr)
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
||||
if exists('g:loaded_devicons') | finish | endif
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" TODO change so its easier to get
|
||||
let g:nvim_web_devicons = 1
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
let g:loaded_devicons = 1
|
||||
@ -0,0 +1,68 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/sh
|
||||
|
||||
## Credit: @B0o (Maddison Hellstrom)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
function get_icon_names() {
|
||||
curl 'https://raw.githubusercontent.com/kyazdani42/nvim-web-devicons/master/lua/nvim-web-devicons.lua' |
|
||||
lua -e '
|
||||
pats={}
|
||||
for name in pairs(dofile().get_icons()) do
|
||||
table.insert(pats, name)
|
||||
end
|
||||
table.sort(pats)
|
||||
print(table.concat(pats, "\n"))
|
||||
'
|
||||
}
|
||||
|
||||
function main() {
|
||||
local tmp
|
||||
tmp="$(mktemp -d)"
|
||||
# shellcheck disable=2064
|
||||
trap "rmdir '$tmp'" EXIT
|
||||
cd "$tmp"
|
||||
local file
|
||||
local -A filetypes=()
|
||||
local -a missing=()
|
||||
while read -r pat; do
|
||||
echo "$pat" >&2
|
||||
if [[ "$pat" =~ ^\. ]]; then
|
||||
file="$pat"
|
||||
else
|
||||
file="test.$pat"
|
||||
fi
|
||||
touch "./$file"
|
||||
local ft
|
||||
ft="$(/usr/bin/nvim -u NORC --noplugin --headless "./$file" +'lua
|
||||
local ok, err = pcall(vim.fn.writefile, { vim.bo.filetype }, "/dev/stdout")
|
||||
if not ok then
|
||||
print(err .. "\n")
|
||||
vim.cmd "cquit"
|
||||
end
|
||||
vim.cmd "quit"
|
||||
')"
|
||||
rm "./$file"
|
||||
if [[ -n "$ft" ]]; then
|
||||
if [[ -v filetypes["$ft"] ]]; then
|
||||
filetypes["$ft"]="${filetypes["$ft"]}, '$pat'"
|
||||
else
|
||||
filetypes["$ft"]="'$pat'"
|
||||
fi
|
||||
else
|
||||
missing+=("$pat")
|
||||
fi
|
||||
done < <(get_icon_names)
|
||||
|
||||
echo "local filetypes = {"
|
||||
for ft in "${!filetypes[@]}"; do
|
||||
echo " ['$ft'] = { ${filetypes[$ft]} },"
|
||||
done
|
||||
echo "}"
|
||||
echo
|
||||
echo "local missing = {"
|
||||
printf " '%s',\n" "${missing[@]}"
|
||||
echo "}"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@ -0,0 +1,206 @@
|
||||
-- Plugin lifepillar/vim-colortemplate must be available on &runtimepath
|
||||
--
|
||||
-- The current working directory must be set to the repo root
|
||||
|
||||
-- IMPORTANT: the `cterm_color` key must always be below the `color` key of the
|
||||
-- same icon. Currently they are.
|
||||
|
||||
-- This file should be run from the shell with `make colors`
|
||||
|
||||
local fn = vim.fn
|
||||
|
||||
--- Exit vim
|
||||
--- @param msg string
|
||||
--- @param rc number
|
||||
local function error_exit(msg, rc)
|
||||
print(msg .. "\n")
|
||||
vim.cmd("cq " .. rc)
|
||||
end
|
||||
|
||||
if not jit then
|
||||
error_exit("Neovim must be LuaJIT-enabled to source this script", 1)
|
||||
end
|
||||
|
||||
if fn.filereadable "lua/nvim-web-devicons.lua" == 0 then
|
||||
error_exit("lua/nvim-web-devicons.lua not found", 1)
|
||||
end
|
||||
|
||||
local rc, err = pcall(vim.fn["colortemplate#colorspace#approx"], "#000000")
|
||||
if not rc then
|
||||
error_exit(err .. "\nlifepillar/vim-colortemplate not present in &runtimepath '" .. vim.o.runtimepath .. "'", 1)
|
||||
end
|
||||
|
||||
-- Needed in order to have the correct indentation on line insertion
|
||||
vim.o.autoindent = true
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Local functions
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local light78 = 255 * 7 / 8
|
||||
local light68 = 255 * 6 / 8
|
||||
local light58 = 255 * 5 / 8
|
||||
local light12 = 255 / 2
|
||||
local light13 = 255 / 3
|
||||
|
||||
local function darken_color(rrggbb)
|
||||
local r, g, b = rrggbb:match "%#(%x%x)(%x%x)(%x%x)"
|
||||
r, g, b = tonumber("0x" .. r), tonumber("0x" .. g), tonumber("0x" .. b)
|
||||
-- luminance formula: see https://stackoverflow.com/a/596243
|
||||
local lum = 0.299 * r + 0.587 * g + 0.114 * b
|
||||
if lum < light13 then -------------------- darkest tertile
|
||||
return rrggbb
|
||||
elseif lum < light12 then ---------------- second darkest quartile
|
||||
r = bit.tohex(r / 4 * 3):sub(-2)
|
||||
g = bit.tohex(g / 4 * 3):sub(-2)
|
||||
b = bit.tohex(b / 4 * 3):sub(-2)
|
||||
elseif lum < light58 then ---------------- lightest octiles: first
|
||||
r = bit.tohex(r / 3 * 2):sub(-2)
|
||||
g = bit.tohex(g / 3 * 2):sub(-2)
|
||||
b = bit.tohex(b / 3 * 2):sub(-2)
|
||||
elseif lum < light68 then ---------------- lightest octiles: second
|
||||
r = bit.tohex(r / 2):sub(-2)
|
||||
g = bit.tohex(g / 2):sub(-2)
|
||||
b = bit.tohex(b / 2):sub(-2)
|
||||
elseif lum < light78 then ---------------- lightest octiles: third
|
||||
r = bit.tohex(r / 3):sub(-2)
|
||||
g = bit.tohex(g / 3):sub(-2)
|
||||
b = bit.tohex(b / 3):sub(-2)
|
||||
else ------------------------------------- lightest octile
|
||||
r = bit.tohex(r / 5):sub(-2)
|
||||
g = bit.tohex(g / 5):sub(-2)
|
||||
b = bit.tohex(b / 5):sub(-2)
|
||||
end
|
||||
return string.format("#%s%s%s", r, g, b)
|
||||
end
|
||||
|
||||
local function update_cterm_colors()
|
||||
-- move to first line
|
||||
vim.cmd ":1"
|
||||
local last = 0
|
||||
|
||||
while true do
|
||||
local cur = fn.search "^\\s*color ="
|
||||
if cur < last then
|
||||
break
|
||||
end
|
||||
last = cur
|
||||
local color = vim.api.nvim_get_current_line():match "%#......"
|
||||
local cterm_color = fn["colortemplate#colorspace#approx"](color).index
|
||||
if fn.search "^\\s*cterm_color" == cur + 1 then
|
||||
vim.cmd(string.format("s/=.*/= %q,", cterm_color))
|
||||
else
|
||||
vim.cmd(tostring(cur))
|
||||
vim.cmd.normal(string.format("octerm_color = %q,", cterm_color))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function generate_lines()
|
||||
local start = fn.line "." - 1
|
||||
fn.search "^}"
|
||||
local finish = fn.line "."
|
||||
local lines = vim.api.nvim_buf_get_lines(fn.bufnr(), start, finish, true)
|
||||
for i = 1, #lines do
|
||||
if lines[i]:find "^%s*color =" then
|
||||
local rrggbb = lines[i]:match '"(#%x%x%x%x%x%x)"'
|
||||
if not rrggbb then
|
||||
error_exit(string.format("invalid color at line %s: '%s'", i, lines[i]), 1)
|
||||
end
|
||||
lines[i] = lines[i]:gsub(rrggbb, darken_color)
|
||||
end
|
||||
end
|
||||
table.insert(lines, "")
|
||||
return lines
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Generate file with icons for light backgrounds
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
if fn.filereadable "lua/nvim-web-devicons/icons-default.lua" == 0 then
|
||||
error_exit("lua/nvim-web-devicons/icons-default.lua not found", 1)
|
||||
end
|
||||
|
||||
vim.cmd "noswapfile drop lua/nvim-web-devicons/icons-default.lua"
|
||||
|
||||
print "Generating file with icons for light backgrounds..."
|
||||
|
||||
-- move to first line
|
||||
vim.cmd ":1"
|
||||
|
||||
-- first table
|
||||
if fn.search("^local icons_by_filename", "c") == 0 then
|
||||
error_exit("Table 'icons_by_filename' not found in lua/nvim-web-devicons/icons-default.lua", 1)
|
||||
end
|
||||
local lines = generate_lines()
|
||||
|
||||
-- second table
|
||||
if fn.search("^local icons_by_file_extension", "c") == 0 then
|
||||
error_exit("Table 'icons_by_file_extension' not found in lua/nvim-web-devicons/icons-default.lua", 1)
|
||||
end
|
||||
local lines2 = generate_lines()
|
||||
|
||||
-- third table
|
||||
if fn.search("^local icons_by_operating_system", "c") == 0 then
|
||||
error_exit("Table 'icons_by_operating_system' not found in lua/nvim-web-devicons/icons-default.lua", 1)
|
||||
end
|
||||
local lines3 = generate_lines()
|
||||
|
||||
-- fourth table
|
||||
if fn.search("^local icons_by_desktop_environment", "c") == 0 then
|
||||
error_exit("Table 'icons_by_desktop_environment' not found in lua/nvim-web-devicons/icons-default.lua", 1)
|
||||
end
|
||||
local lines4 = generate_lines()
|
||||
|
||||
-- fifth table
|
||||
if fn.search("^local icons_by_window_manager", "c") == 0 then
|
||||
error_exit("Table 'icons_by_window_manager' not found in lua/nvim-web-devicons/icons-default.lua", 1)
|
||||
end
|
||||
local lines5 = generate_lines()
|
||||
|
||||
table.insert(lines5, "return {")
|
||||
table.insert(lines5, " icons_by_filename = icons_by_filename,")
|
||||
table.insert(lines5, " icons_by_file_extension = icons_by_file_extension,")
|
||||
table.insert(lines5, " icons_by_operating_system = icons_by_operating_system,")
|
||||
table.insert(lines5, " icons_by_desktop_environment = icons_by_desktop_environment,")
|
||||
table.insert(lines5, " icons_by_window_manager = icons_by_window_manager,")
|
||||
table.insert(lines5, "}")
|
||||
|
||||
-- write both tables to file
|
||||
fn.writefile(lines, "lua/nvim-web-devicons/icons-light.lua")
|
||||
fn.writefile(lines2, "lua/nvim-web-devicons/icons-light.lua", "a")
|
||||
fn.writefile(lines3, "lua/nvim-web-devicons/icons-light.lua", "a")
|
||||
fn.writefile(lines4, "lua/nvim-web-devicons/icons-light.lua", "a")
|
||||
fn.writefile(lines5, "lua/nvim-web-devicons/icons-light.lua", "a")
|
||||
|
||||
print "Finished creating new file!"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Update cterm colors for dark background
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
print "Generating cterm colors for dark background...\n"
|
||||
|
||||
update_cterm_colors()
|
||||
|
||||
vim.cmd "wall!"
|
||||
print "Finished!"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Generate cterm colors for light background
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
if fn.filereadable "lua/nvim-web-devicons/icons-light.lua" == 0 then
|
||||
error_exit("lua/nvim-web-devicons/icons-light.lua not found", 1)
|
||||
end
|
||||
|
||||
vim.cmd "noswapfile drop lua/nvim-web-devicons/icons-light.lua"
|
||||
|
||||
print "Generating cterm colors for light background...\n"
|
||||
|
||||
update_cterm_colors()
|
||||
|
||||
vim.cmd ":1"
|
||||
vim.cmd "wall!"
|
||||
print "Finished!\n"
|
||||
Reference in New Issue
Block a user