Created
October 4, 2020 11:43
-
-
Save austintraver/b61cedd84b5ef0582bd3bd5f6c188ff7 to your computer and use it in GitHub Desktop.
Download fonts straight from your CLI
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
| # usage: `zsh ./fontastic.sh 'Open Sans'` | |
| font_family=${1/ /+} | |
| font_weights=({1..9}00{,b,i,bi}) | |
| base_url='https://fonts.googleapis.com/css' | |
| query_string="family=${font_family}:${(j<,>)font_weights}" | |
| endpoint="${base_url}?${query_string}" | |
| fonts=($(curl -s ${endpoint} | grep -o 'https://.*\.ttf' )) | |
| names=(${(f)"$(curl -s ${endpoint} | grep '^ src' | sed "s/^.*src: local('\([^']\+\)').*$/\1/")"}) | |
| if (( ${#fonts} > 0 )) { | |
| mkdir -v ${1} | |
| pushd ${1} | |
| for ((i=1;i<=${#fonts};i+=1)); { | |
| /usr/bin/curl -s ${fonts[$i]} -o "${names[$i]}.ttf" | |
| } | |
| popd | |
| print "font files have been saved to ${1:A}" | |
| exit 0 | |
| } else { | |
| print "error: no results found for font family ${1}" >&1 | |
| exit 1 | |
| } | |
| popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment