Nerdfix Save

🔣 nerdfix helps you to find/fix obsolete Nerd Font icons in your project.

Project README

🔣 nerdfix

GitHub Release GitHub Workflow Status

nerdfix helps you to find/fix obsolete Nerd Font icons in your project.

💭 Why

Nerd Fonts is used in many projects for a beautiful UI. It provides more than 10,000 icons, but some codepoints conflict with other fonts (especially CJK fonts). To ensure that the icons remain in the private use area, Nerd Fonts has changed the codepoints of some icons in recent releases, for example, mdi-* icons (including over 2,000 icons) are deprecated since v2.3.3 and will be removed in v3.

These icons are marked as obsolete in the official cheat sheet and it's recommended to replace them with the new ones. However, you may find it boring to check all the used icons one by one, so nerdfix was written to index the cheat sheet and find obsolete icons in your project.

⚙️ Installation

You can download the pre-built binaries from the release page or manually build this project manually from source.

In addition, the binaries come with a recently updated cheat sheet and you can overwrite it with the latest one using nerdfix -i /path/to/your/file (follow this link to get the latest file).

Install from source

You can build and install from the source code with cargo:

cargo install --git https://github.com/loichyan/nerdfix.git

Or with nix:

nix run github:loichyan/nerdfix

📋 Note

Please make sure you're using Nerd Fonts after v2.3.3, otherwise the replaced new icons may not be displayed correctly. If you are a plugin author, it's also recommended to notify this in updates.

🔍 Usage

The check command checks input files and reports obsolete icons with some suggestions (sorted by similarity) that you could replace them with.

nerdfix check test/test-data.txt

You get the output as follows:

warning: Found obsolete icon U+F752
  ┌─ tests/test-data.txt:1:27
  │
1 │ mdi-folder_multiple = ""
  │                           ^ Icon 'mdi-folder_multiple' is marked as obsolete
  │
  = You could replace it with:
        1. 󰉓 U+F0253 md-folder_multiple
        2. 󱏓 U+F13D3 md-folder_star_multiple
        ...

Interactive patching

The fix command reports the same information as check and displays a prompt asking the user to input a new icon to replace the obsolete one.

warning: Found obsolete icon U+F719
  ┌─ tests/test-data.txt:4:29
  │
4 │ mdi-file_document_box = ""
  │                             ^ Icon 'mdi-file_document_box' is marked as obsolete
  │
  = You could replace it with:
        1. 󰈙 U+F0219 md-file_document
        2. 󰷈 U+F0DC8 md-file_document_edit
        ...
> Input an icon: 1
# Your input: 󰈙

The prompt accepts several types of input:

Type Example
Suggestion number 1
Codepoint U+F0219
Icon name md-file_document
Icon character 󰈙

Fuzzy autocompletion/search

The prompt also provides fuzzy matching suggestions when you type the icon name:

> Input an icon: documentmultiple
  󱔗 md-file_document_multiple
  󱔘 md-file_document_multiple_outline
  󰡟 md-comment_multiple
  ...

You can also use the search command to call the prompt directly for a fuzzy search.

Autofix

nerdfix provides some features to automatically patch obsolete icons:

  • The last user input is picked if an icon appears twice.
  • Use --sub FROM/TO (or --sub exact:FROM/TO for full syntax) to replace one icon with another, e.g. mdi-tab is replaced with md-tab when --sub mdi-tab/md-tab is specified.
  • Use --sub prefix:FROM/TO to replace the prefix of an icon name with another, e.g. mdi-tab is replaced with md-tab when --sub prefix:mdi-/md- is specified.

Database

nerdfix accepts icons and substutitions in the following JSON format:

{
  "icons": [
    { "name": "md-file_document", "codepoint": "f0219" },
    { "name": "mdi-file_document_box", "codepoint": "0f719", "obsolete": true }
  ],
  "substitutions": ["exact:mdi-file_document_box/md-file_document"]
}

As mentioned above, the precompiled nerdfix binary comes bundled with an indexed database that includes all available icons and some common substitutions.

Structured output

You can use check --format json to get structured output for further use. nerdfix prints diagnostics with the following fields line by line:

Field Description
severity Severity of a diagnostic
path Source file of a diagnostic
type Diagnostic type, currently only obsolete is supported
span Byte index span of an obsolete icon
name Icon name
codepoint Icon codepoint

💬 FAQ

How can I find all files that contain obsolete icons?

nerdfix check --format=json -r /path/to/root 2>/dev/null |
  jq -s -r '[.[].path] | sort | unique | .[]'

How can I save patched content to a file other than the input? (#7)

nerdfix fix /path/to/input:/path/to/output

How can I recursively traverse all directories? (#5)

nerdfix fix --recursive /path/to/root
# Or use fd/find
nerdfix fix $(fd -t f . /path/to/root)

How can I skip interactive prompts? (#3)

nerdfix fix --write --select-first /path/to/file

⚖️ License

Licensed under either of

at your option.

Open Source Agenda is not affiliated with "Nerdfix" Project. README Source: loichyan/nerdfix
Stars
404
Open Issues
0
Last Commit
5 months ago
Repository
License

Open Source Agenda Badge

Open Source Agenda Rating