Skip to content

Instantly share code, notes, and snippets.

@nihilismus
Last active June 11, 2020 15:45
Show Gist options
  • Save nihilismus/5f84ef63ba607926105f837862b31448 to your computer and use it in GitHub Desktop.
Save nihilismus/5f84ef63ba607926105f837862b31448 to your computer and use it in GitHub Desktop.
Bash script to install the latest version of Nerd Fonts (https://www.nerdfonts.com) from its GitHub repository.
#!/usr/bin/env bash
# Copyright © 2020 Antonio Hernández Blas <[email protected]>
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
set -e
mkdir -p $HOME/.local/share/fonts/nerd-fonts
cd $HOME/.local/share/fonts/nerd-fonts
wget -o /dev/null -O - "https://github.com/ryanoasis/nerd-fonts/releases/latest" 2>/dev/null \
| grep -E 'ryanoasis/nerd-fonts/releases/download/.*/.*\.zip' \
| sed 's|^.*ryanoasis/|https://github.com/ryanoasis/|' \
| sed 's|\.zip".*$|.zip|' \
| grep -v 'MPlus.zip' \
| grep -v 'Noto.zip' \
> nerd-fonts.url
last_release="$(basename $(dirname $(head -1 nerd-fonts.url)))"
if [ -z "$last_release" ]; then
echo " Nerd Fonts last release could not be resolved."
exit 1
fi
if [ -f "$last_release.done" ]; then
echo " Nerd Fonts $last_release already installed."
exit 0
fi
set -u
# Download ZIP files
wget -ci nerd-fonts.url
# Delete old fonts, if any.
rm -f *.ttf *.TTF *.otf *.OTF
# Uncompress all ZIP files
for zipfile in *.zip; do
unzip -o "$zipfile" || true
done
# Delete all ZIP files
rm -f *.zip
# Delete Windows Fonts
find . -iname "*Windows*Compatible*" -exec rm -f {} \;
# Prefer OTF over TTF
ls -1 *.ttf 2>/dev/null | while read ttf_file; do
otf_file="$(echo $ttf_file | sed 's/\.ttf$/.otf/')"
if [ -f "${otf_file}" ]; then
echo "rm -f ${ttf_file}"
rm -f "${ttf_file}"
fi
done
# Regenerate fontconfig's cache
fc-cache -rfv || true
rm -f nerd-fonts.url
rm -f *.done
touch $last_release.done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment