Skip to content

Instantly share code, notes, and snippets.

@kevin-lee
Created February 25, 2017 10:38
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevin-lee/328e9993d6b3ad250636023fb2c7827f to your computer and use it in GitHub Desktop.
Save kevin-lee/328e9993d6b3ad250636023fb2c7827f 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"
@PopovYuriy
Copy link

Hi! In my case, had to add some things:
for .TTF and .TTC
%code%
-or -name '.[O,T]TF'
-or -name '
.[O,T]TC'
%code%

It may be helpfull to you:)

@thenoobtester
Copy link

thenoobtester commented Nov 29, 2020

Thank you @PopovYuriy, it was helpful but in my case it needed an asterisk like this:

-or -name '*.[O,T]TF'
-or -name '*.[O,T]TC'

And thank you to @kevin-lee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment