Last active
June 1, 2024 05:34
-
-
Save jessenich/9b39b229b8f9cbbeed5059d60beed014 to your computer and use it in GitHub Desktop.
Install Nerd Fonts (Linux)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
__main() { | |
declare -a fonts=("Hack") | |
gh_release=$(curl -s "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest") | |
if [[ "${fonts[0]}" = "all" ]]; then | |
# Project all font names into source array | |
echo "$gh_release" | \ | |
jq -r '.assets | .[].name | rtrimstr(".zip")' | \ | |
while IFS="" read -r font; do fonts+=($font); done | |
else | |
fonts=("$@") | |
fi | |
version=$(echo "$gh_release" | jq -r '.tag_name | ltrimstr("v")') | |
fonts_dir="${XDG_DATA_HOME:-$HOME/.local/share}/fonts" | |
mkdir -p "$fonts_dir" | |
for font in "${fonts[@]}"; do | |
download_url="https://github.com/ryanoasis/nerd-fonts/releases/download/$version/$font.zip" | |
echo "Downloading $download_url" | |
curl -fsSL "$download_url" -o "/tmp/$font.zip" | |
unzip "/tmp/$font.zip" -d "$fonts_dir" | |
rm -f "/tmp/$font.zip" | |
done | |
find "$fonts_dir" -name '*Windows Compatible*' -delete | |
fc-cache -fv | |
} | |
__main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment