This Ruby script automates the installation of Nerd Fonts from links stored in a fonts.json
file. It allows the user to select which fonts to install, downloads/unzips the files directly into the system font directory (~/.fonts
), and handles URL redirects. After installation, the script also updates the system's font cache.
- Allows users to select fonts by number or range (e.g.,
1,4,5
or5-12,14
). - Supports both individual font selection and ranges of fonts.
- Automatically follows HTTP redirects to ensure successful downloads.
- Extracts downloaded zip files and installs fonts into the system font directory.
- Updates the system font cache after installation.
- Default version is set to
3.2.1
, but the user can specify another version using command-line options.
first of all, you need to install a Ruby version described in .tool-versions
file. If you use asdf-vm as a package manager, you just download a Ruby version, according with this file.
To install the required gems, run:
bundle install
-v
or--version
: Allows the user to specify the font version to download. If not specified, the default version3.2.1
is used.
Example usage:
ruby install.rb -v 3.0.0
After running the script, you will be prompted to select which fonts to install. You can either:
- Specify individual font numbers (e.g.,
1,4,5
). - Specify ranges of fonts (e.g.,
5-12,14
). - A combination of individual numbers and ranges.
Note: Option 0
to select all fonts is displayed.
Loads the fonts.json
file and parses the font data.
Handles HTTP redirects, following up to 10 redirects to ensure the correct URL is reached.
Downloads the font zip file from the provided URL, extracts it, and installs the font into the specified directory.
- Downloads are saved in the user's
~/.fonts
directory. - If the download results in a file with zero size, the script will abort that specific download.
Processes user input for font selection, supporting both ranges and individual numbers.
Handles the command-line argument for specifying the version of the fonts.
Iterates through the user-selected fonts, downloads, and installs them into the system.
After installation, the script runs the fc-cache -f
command to refresh the system font cache, ensuring the new fonts are available.
-
Run the script:
ruby install.rb -v 3.2.1
-
The script will display a list of fonts:
Select the fonts you want to install (e.g., 1-5,7,10-12): 0. ALL FONTS 1. 0xProto 2. 3270 3. Agave ...
-
Enter your selection, for example:
1-3,5,7
-
The script will download, extract, and install the selected fonts, then update the font cache.
- The option
0
for selecting all fonts is displayed but not yet implemented.
This script is open-source and available under the MIT license.