Skip to content

Instantly share code, notes, and snippets.

@Ghasak
Forked from kevin-lee/README.md
Created April 20, 2022 16:57
Show Gist options
  • Save Ghasak/612f1886f4da34599e3495e281197947 to your computer and use it in GitHub Desktop.
Save Ghasak/612f1886f4da34599e3495e281197947 to your computer and use it in GitHub Desktop.
Shellscript to install fonts for macOS and Linux

How to Use

# Move the the folder where the fonts are available. This script supports only otf and ttf.
# Then simply run the script like
$ ./path/to/script/install-fonts.sh 

Or you can add an alias to the ~/.bashrc or ~/.zshrc

alias install-fonts='/path/to/script/install-fonts.sh' 

Then

$ install-fonts 

To install the fonts.

Too easy!

#!/bin/bash
the_fonts_dir=$(pwd)
echo "the_fonts_dir: $the_fonts_dir"
find_command="find \"$the_fonts_dir\" \( -name '*.[o,t]tf' -or -name '*.pcf.gz' \) -type f -print0"
if [[ `uname` == 'Darwin' ]]; then
# MacOS
font_dir="$HOME/Library/Fonts"
else
# Linux
font_dir="$HOME/.local/share/fonts"
mkdir -p $font_dir
fi
echo -e "Run: $find_command | xargs -0 -I % cp \"%\" \"$font_dir/\"\n"
# Copy all fonts to user fonts directory
echo "Copying fonts..."
# printing
eval $find_command | xargs -0 -I %
eval $find_command | xargs -0 -I % cp "%" "$font_dir/"
# Reset font cache on Linux
if command -v fc-cache @>/dev/null ; then
echo -e "\nResetting font cache, this may take a moment..."
fc-cache -f $font_dir
fi
echo -e "\nAll fonts have been installed to $font_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment