Skip to content

Commit

Permalink
refactor: split tables into individual files (#550)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Courtis <[email protected]>
Co-authored-by: hasecilu <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2025
1 parent 4567e0d commit 4b0d255
Show file tree
Hide file tree
Showing 24 changed files with 1,849 additions and 1,845 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lua/nvim-web-devicons/light/* linguist-generated=true
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ read_globals = {
"MiniAlign",
}

files["lua/nvim-web-devicons/icons-*.lua"].max_line_length = 200
files["lua/nvim-web-devicons/*/icons_*.lua"].max_line_length = 200
2 changes: 1 addition & 1 deletion .styluaignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lua/nvim-web-devicons/icons-*.lua
lua/nvim-web-devicons/*/icons_*.lua
83 changes: 37 additions & 46 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

Thank you for your contribution!

## Order

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*.
Expand All @@ -24,8 +19,43 @@ or via your OS package manager e.g. *Arch Linux*:
pacman -S stylua luacheck
```

## Adding icons

Add or update icons in `lua/nvim-web-devicons/default/` directory

There are five files where icons can be added:

1. `icons_by_filename.lua`
2. `icons_by_file_extension.lua`
3. `icons_by_operating_system.lua`
4. `icons_by_desktop_environment.lua`
5. `icons_by_window_manager.lua`

Add the icon to table in file **1.** if the icon is for a file that is always named that way, for example `.gitconfig`.
Add the icon to table in file **2.** if the icon is for all files with an extension, for example `vim`.
Add the icon to table in files **3.**, **4.** and **5.** if the icon is from an OS, DE or WM.

Each icon must have the following structure (this is an example):

```lua
[".gitconfig"] = { icon = "", color = "#41535b", cterm_color = "0", name = "GitConfig" },
```

> [!IMPORTANT]
> Make sure each icon association occupies exactly one line.
***All of the following keys are required:***

- `icon` glyph
- `color` must contain a color in the html notation
- `cterm_color` must contain a number (any number)
- the correct value for `cterm_color` will be generated by the script in next step
- `name` must only contain alphanumeric characters (don't use `/`, `-`, `_`)

## Building

Note: Ensure your current working directory is the repo root.

Following your changes, please run:

```sh
Expand All @@ -34,7 +64,7 @@ make

This will:

1. `git clone --depth 1 https://github.com/lifepillar/vim-colortemplate.git vim-colortemplate` if necessary
1. Install required plugins: [vim-colortemplate](https://github.com/lifepillar/vim-colortemplate.git) and [mini.align](https://github.com/echasnovski/mini.align) if necessary
2. Generate cterm colors
3. Generate light color variants
4. Check style
Expand All @@ -47,46 +77,7 @@ You can automatically fix any style issues via:
make style-fix
```

## Generate Colors

Add or update icons in `lua/nvim-web-devicons/icons-default.lua`

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.

Each icon must have the following structure (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`
Please commit all files from `lua/nvim-web-devicons/default/`, `lua/nvim-web-devicons/light/` end `lua/nvim-web-devicons/filetypes.lua`

## Test

Expand Down
22 changes: 12 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
VIM_COLORTEMPLATE_VERSION = 2.2.3
VIM_MINI_ALIGN_VERSION = 0.14.0

all: colors style-check lint filetypes
all: generate style-check lint filetypes

colors: vim-colortemplate mini-align
rm lua/nvim-web-devicons/icons-light.lua
cp lua/nvim-web-devicons/icons-default.lua lua/nvim-web-devicons/icons-light.lua
generate: vim-colortemplate mini-align
rm -f lua/nvim-web-devicons/light/icons_by_*.lua
cp lua/nvim-web-devicons/default/icons_by_*.lua lua/nvim-web-devicons/light/
nvim \
--clean \
--headless \
--cmd "set rtp^=vim-colortemplate" \
--cmd "set rtp^=mini-align" \
-c 'source scripts/generate_colors.lua' \
-c 'source scripts/align_spaces.lua' \
-c 'source scripts/generate.lua' \
-c 'source scripts/align.lua' \
-c 'source scripts/sort_filetypes.lua' \
-c 'qall'

colors-check: colors
git diff --exit-code lua/nvim-web-devicons/icons-default.lua
git diff --exit-code lua/nvim-web-devicons/icons-light.lua
colors-check: generate
git diff --exit-code lua/nvim-web-devicons/default/
git diff --exit-code lua/nvim-web-devicons/light/
git diff --exit-code lua/nvim-web-devicons/filetypes.lua

vim-colortemplate:
mkdir -p vim-colortemplate
Expand All @@ -43,4 +45,4 @@ clean:
rm -rf vim-colortemplate
rm -rf mini-align

.PHONY: all colors style-check style-fix lint filetypes
.PHONY: all clean generate colors-check style-check style-fix lint filetypes
Loading

0 comments on commit 4b0d255

Please sign in to comment.