Skip to content

Instantly share code, notes, and snippets.

@tororutsu
Created May 21, 2026 19:51
Show Gist options
  • Select an option

  • Save tororutsu/0b76a2048e35e052c5a3f3006ba263bc to your computer and use it in GitHub Desktop.

Select an option

Save tororutsu/0b76a2048e35e052c5a3f3006ba263bc to your computer and use it in GitHub Desktop.
Elvish Nerd Font Installer
#!/usr/bin/env elvish
use str
var list-file = "fonts.txt"
# Verify our text file exists before proceeding
try {
test -f $list-file
} catch {
echo "Could not find "$list-file
echo "Please create it with one Nerd Font name per line (e.g., FiraCode, Hack)."
exit 1
}
# In Elvish, capturing command output like `cat` inside brackets `[]`
# implicitly splits the output by lines into a list.
var fonts = [(cat $list-file)]
for font $fonts {
# Remove any stray spaces or carriage returns (\r)
var clean-font = (str:trim-space $font)
# Check that the line isn't empty (!=s is the string inequality operator)
if (!=s $clean-font "") {
# Define the path using the $HOME environment variable
var target-dir = $E:HOME"/.local/share/fonts/NerdFonts/"$clean-font
if ?(test -d $target-dir) {
echo "==> "$clean-font" is already installed. Skipping..."
continue
}
echo "==> Installing "$clean-font"..."
mkdir -p $target-dir
var url = "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.4.0/"$clean-font".tar.xz"
# Download and pipe directly to tar:
# -fL: fail silently on 404s, follow GitHub redirects
# -xJ: extract .xz archive
# -f -: read from stdin (the pipe)
# -C: extract directly into the target directory
try {
curl -fL $url | tar -xJ -f - -C $target-dir
echo "==> Finished "$clean-font"\n"
} catch {
echo "==> Error downloading "$url" Check the spelling in your list.\n"
# Cleanup the empty directory so it doesn't falsely trigger the skip check next time
rm -rf $target-dir
}
}
}
echo "Updating system font cache..."
fc-cache -fv
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment