diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9299e9ee..e5df8bbdc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,3 +52,16 @@ jobs: - name: make colors-check run: make colors-check + filetypes: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + + - name: make filetypes + env: + VIMRUNTIME: /home/runner/nvim-stable/share/nvim/runtime + run: make filetypes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a9cf5c9be..4945ab38e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,22 +4,24 @@ Thank you for your contribution! ## Order -Please ensure `icons_by_filename`, `icons_by_file_extension` and `filetypes` are ordered alphabetically, to prevent merge conflicts. +Please ensure `icons_by_filename`, `icons_by_file_extension`, `icons_by_operating_system`, `icons_by_desktop_environment`, +`icons_by_window_manager` and `filetypes` are ordered alphabetically, to prevent merge conflicts. ## Prerequisites -Code is formatted using stylua and linted using luacheck. +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: +or via your OS package manager e.g. *Arch Linux*: + ```sh -pacman -S stylua -pacman -S luacheck +pacman -S stylua luacheck ``` ## Building @@ -31,13 +33,16 @@ 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 +2. Generate cterm colors +3. Generate light color variants +4. Check style +5. Lint +6. Find missing filetypes You can automatically fix any style issues via: + ```sh make style-fix ``` @@ -46,15 +51,20 @@ make style-fix 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 +There are five tables where icons can be added: + +1. `icons_by_filename` +2. `icons_by_file_extension` +3. `icons_by_operating_system` +4. `icons_by_desktop_environment` +5. `icons_by_window_manager` + +Add the icon to table **1.** if the icon is for a file that is always named that way, for example `.gitconfig`. +Add the icon to table **2.** if the icon is for all files with an extension, for example `vim`. +Add the icon to table **3.**, **4.**, **5.** if the icon is from an OS, DE or WM. -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 structure (this is an example): -Each icon must have the following (this is an example): ```lua [".gitconfig"] = { icon = "", @@ -63,15 +73,16 @@ Each icon must have the following (this is an example): name = "GitConfig", }, ``` -___Key/value pairs must appear in the same exact order!___ + +***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: +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` @@ -81,7 +92,7 @@ Please commit both `lua/nvim-web-devicons/icons-default.lua` and `lua/nvim-web-d Run `:NvimWebDeviconsHiTest` to view the icons and their highlighting. -Start neovim with `TERM=xterm-256color nvim ...` to test cterm. +Start *Neovim* with `TERM=xterm-256color nvim ...` to test cterm. Check with `&background` `dark` and `light` @@ -89,36 +100,39 @@ Check with `&background` `dark` and `light` When modifying or adding API, please update [Usage](README.md#Usage) -# Pull Request +## 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. +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. +A [Conventional Commits] subject will be validated by the Semantic Pull Request Subject CI job. +Reference the issue to be used in the release notes e.g. -``` +```txt 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 + +- 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. @@ -130,7 +144,9 @@ It is useful to see the actual glyphs in the pull request. That can be done by s 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" +- 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" + +[Conventional Commits]: diff --git a/Makefile b/Makefile index 5f3344b0f..080ff1456 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VIM_COLORTEMPLATE_VERSION = 2.2.3 -all: colors style-check lint +all: colors style-check lint filetypes colors: vim-colortemplate nvim \ @@ -26,7 +26,10 @@ style-fix: lint: luacheck lua scripts +filetypes: + ./scripts/filetypes.sh + clean: rm -rf vim-colortemplate -.PHONY: all colors style-check style-fix lint +.PHONY: all colors style-check style-fix lint filetypes diff --git a/README.md b/README.md index 1922f9063..4719a4e81 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,7 @@ -# 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 -Provides [Nerd Font](https://www.nerdfonts.com/) [1] icons (glyphs) for use by neovim plugins: +Provides [Nerd Font](https://www.nerdfonts.com/) [^1] icons (glyphs) for use by *Neovim* plugins: + - Icons by: - Extension - Full name @@ -15,7 +11,13 @@ Provides [Nerd Font](https://www.nerdfonts.com/) [1] icons (glyphs) f A `lua` fork of [vim-devicons](https://github.com/ryanoasis/vim-devicons). -[1] Not limited to Nerd Font icons: unicode and other fonts may be used. +> [!IMPORTANT] +> 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. + +[^1]: Not limited to Nerd Font icons: unicode and other fonts may be used. ## Requirements @@ -30,10 +32,16 @@ Plug 'nvim-tree/nvim-web-devicons' or with [packer.nvim](https://github.com/wbthomason/packer.nvim) -``` +```lua use 'nvim-tree/nvim-web-devicons' ``` +or with [lazy.nvim](https://github.com/folke/lazy.nvim) + +```lua +{ "nvim-tree/nvim-web-devicons", opts = {} }, +``` + [![LuaRocks](https://img.shields.io/luarocks/v/nvim-tree/nvim-web-devicons?logo=lua&color=purple)](https://luarocks.org/modules/nvim-tree/nvim-web-devicons) ## Usage @@ -48,6 +56,7 @@ Light or dark color variants of the icons depend on `&background`. The variant can also be set manually in `setup` with the `variant` option. The variant is updated: + - on `OptionSet` event for `background`, or - after explicitly calling `require("nvim-web-devicons").refresh()`. @@ -68,7 +77,7 @@ if the color scheme changes ```lua require'nvim-web-devicons'.setup { - -- your personnal icons can go here (to override) + -- your personal 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 = { @@ -126,7 +135,7 @@ require'nvim-web-devicons'.setup { ### Get Icon -Get the icon for a given file by passing in the `name`, the `extension` and an _optional_ options `table`. +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. @@ -146,6 +155,7 @@ 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() ``` @@ -156,6 +166,7 @@ require'nvim-web-devicons'.has_loaded() `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 == "") @@ -220,7 +231,8 @@ or set the icon to use for a filetype with: 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. +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. diff --git a/lua/nvim-web-devicons.lua b/lua/nvim-web-devicons.lua index 843ef1011..7b3024e32 100644 --- a/lua/nvim-web-devicons.lua +++ b/lua/nvim-web-devicons.lua @@ -105,6 +105,7 @@ end local filetypes = { ["apl"] = "apl", ["asm"] = "asm", + ["astro"] = "astro", ["avif"] = "avif", ["bash"] = "bash", ["bib"] = "bib", @@ -154,6 +155,7 @@ local filetypes = { ["eex"] = "eex", ["ejs"] = "ejs", ["elixir"] = "ex", + ["elf"] = "elf", ["elm"] = "elm", ["epuppet"] = "epp", ["erlang"] = "erl", @@ -215,11 +217,13 @@ local filetypes = { ["lock"] = "lock", ["lprolog"] = "sig", ["lua"] = "lua", + ["luau"] = "luau", ["make"] = "makefile", ["markdown"] = "markdown", ["material"] = "material", ["mdx"] = "mdx", ["mint"] = "mint", + ["mojo"] = "mojo", ["motoko"] = "mo", ["mustache"] = "mustache", ["nim"] = "nim", @@ -254,6 +258,7 @@ local filetypes = { ["pyd"] = "pyd", ["pyo"] = "pyo", ["python"] = "py", + ["qml"] = "qml", ["query"] = "query", ["r"] = "r", ["res"] = "rescript", @@ -278,6 +283,7 @@ local filetypes = { ["sqlite3"] = "sqlite3", ["srt"] = "srt", ["ssa"] = "ssa", + ["stp"] = "stp", ["styl"] = "styl", ["sublime"] = "sublime", ["suo"] = "suo", @@ -287,9 +293,11 @@ local filetypes = { ["systemverilog"] = "sv", ["tads"] = "t", ["tcl"] = "tcl", + ["tf"] = "tf", ["templ"] = "templ", ["terminal"] = "terminal", ["tex"] = "tex", + ["tmux"] = "tmux", ["toml"] = "toml", ["tres"] = "tres", ["tscn"] = "tscn", diff --git a/lua/nvim-web-devicons/icons-default.lua b/lua/nvim-web-devicons/icons-default.lua index 1003c0df1..3fce4a296 100644 --- a/lua/nvim-web-devicons/icons-default.lua +++ b/lua/nvim-web-devicons/icons-default.lua @@ -335,12 +335,6 @@ local icons_by_filename = { cterm_color = "135", name = "AUTHORS", }, - ["avif"] = { - icon = "", - color = "#a074c4", - cterm_color = "140", - name = "Avif", - }, ["brewfile"] = { icon = "", color = "#701516", @@ -1214,6 +1208,12 @@ local icons_by_file_extension = { cterm_color = "197", name = "Astro", }, + ["avif"] = { + icon = "", + color = "#a074c4", + cterm_color = "140", + name = "Avif", + }, ["awk"] = { icon = "", color = "#4d5a5e", diff --git a/lua/nvim-web-devicons/icons-light.lua b/lua/nvim-web-devicons/icons-light.lua index 2bf9962b2..9deb62f90 100644 --- a/lua/nvim-web-devicons/icons-light.lua +++ b/lua/nvim-web-devicons/icons-light.lua @@ -335,12 +335,6 @@ local icons_by_filename = { cterm_color = "61", name = "AUTHORS", }, - ["avif"] = { - icon = "", - color = "#6b4d83", - cterm_color = "96", - name = "Avif", - }, ["brewfile"] = { icon = "", color = "#701516", @@ -1214,6 +1208,12 @@ local icons_by_file_extension = { cterm_color = "125", name = "Astro", }, + ["avif"] = { + icon = "", + color = "#6b4d83", + cterm_color = "96", + name = "Avif", + }, ["awk"] = { icon = "", color = "#3a4446", diff --git a/scripts/filetype-generator.sh b/scripts/filetype-generator.sh deleted file mode 100755 index 902c6ef4a..000000000 --- a/scripts/filetype-generator.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/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 "$@" diff --git a/scripts/filetypes.sh b/scripts/filetypes.sh new file mode 100755 index 000000000..bdfaf7984 --- /dev/null +++ b/scripts/filetypes.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +# Iterate over the elements of icons_by_file_extension and check if there are missed filetypes. +# $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset. + +if [ -z "${VIMRUNTIME}" ]; then + export VIMRUNTIME="/usr/share/nvim/runtime" +fi + +exit_value=0 +in_section=false + +while IFS= read -r line; do + if [[ $line =~ ^local\ icons_by_file_extension\ =\ \{$ ]]; then + in_section=true + elif [[ $line =~ ^\}$ ]]; then + in_section=false + fi + + if $in_section && [[ $line =~ \[\"(.+)\"\] ]]; then + key="${BASH_REMATCH[1]}" + # Search for the key in the main file + line=$(grep -F "\"$key\"" "lua/nvim-web-devicons.lua") + if [ -n "$line" ]; then + continue + else + [ -f "${VIMRUNTIME}/syntax/$key.vim" ] && + echo -e "\e[33mPlease add \"$key\" to filetypes Lua table.\e[0m" && + exit_value=1 + fi + fi +done <"lua/nvim-web-devicons/icons-default.lua" +exit $exit_value