Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created August 8, 2023 03:07
Show Gist options
  • Save naranyala/bbdb77f0576a6ba4e47b4d0293174d63 to your computer and use it in GitHub Desktop.
Save naranyala/bbdb77f0576a6ba4e47b4d0293174d63 to your computer and use it in GitHub Desktop.
easy-peasy installing font, directly from nerdfont
#!/bin/bash
# Set font installation directory
font_install_dir="$HOME/.local/share/fonts"
# List of popular Google Fonts available until September 2021
google_fonts=(
"Work Sans"
"Open Sans"
"Roboto"
"Lato"
"Montserrat"
"Source Sans Pro"
"Raleway"
"Noto Sans"
"Poppins"
"Ubuntu"
# Add more options here
)
# Display Google Fonts options
echo "Select a Google Font option:"
select font_option in "${google_fonts[@]}"; do
if [[ " ${google_fonts[@]} " =~ " ${font_option} " ]]; then
chosen_font_name="$font_option"
break
else
echo "Invalid selection. Please choose a valid option."
fi
done
# Convert the selected font name to kebab-case
font_dir_name="$(echo "$chosen_font_name" | tr ' ' '-' | tr '[:upper:]' '[:lower:]')"
# Construct the direct download link using provided API
variants="100,200,300,500,600,700,800,900,100italic,200italic,300italic,regular,italic,500italic,600italic,700italic,800italic,900italic"
direct_download_url="https://gwfh.mranftl.com/api/fonts/$font_dir_name?download=zip&subsets=latin,latin-ext&variants=$variants&formats=ttf"
# Create a new directory for the font
font_dir="$font_install_dir/$font_dir_name"
mkdir -p "$font_dir"
# Download the font files using direct download link if not already downloaded
if [ ! -f "$font_dir/$font_dir_name.zip" ]; then
curl -o "$font_dir/$font_dir_name.zip" "$direct_download_url"
fi
# Extract the downloaded font files if not already extracted
if [ ! -d "$font_dir/$font_dir_name" ]; then
unzip -o "$font_dir/$font_dir_name.zip" -d "$font_dir"
fi
# Rebuild the font cache
fc-cache -fv
echo "Google Font '$chosen_font_name' downloaded and installed, and font cache rebuilt."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment