2018-07-09 16:20:40 +02:00
#!/usr/bin/env bash
2019-11-03 19:05:56 +02:00
# Nerd Fonts Version: 2.1.0
2018-03-03 21:14:22 +02:00
# Script Version: 1.0.0
2016-11-06 05:09:12 +02:00
# Iterates over all patched fonts directories
# to generate ruby cask files for homebrew-fonts (https://github.com/caskroom/homebrew-fonts)
# only adds non-Windows versions of the fonts
2016-11-19 03:28:47 +02:00
#set -x
2016-11-06 05:09:12 +02:00
2019-11-03 19:05:56 +02:00
version = "2.1.0"
2016-11-19 03:28:47 +02:00
patched_parent_dir = "../../patched-fonts/"
2016-11-06 05:09:12 +02:00
homepage = "https://github.com/ryanoasis/nerd-fonts"
2016-11-13 19:22:10 +02:00
downloadarchive = "https://github.com/ryanoasis/nerd-fonts/releases/download/v#{version}/"
sha256sum = ":no_check"
appcast = "https://github.com/ryanoasis/nerd-fonts/releases.atom"
appcastcheckpoint = $( curl --compressed --location --user-agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36' "https://github.com/ryanoasis/nerd-fonts/releases.atom" | sed 's|<pubDate>[^<]*</pubDate>||g' | shasum --algorithm 256 | head -c 64)
2017-05-14 00:02:53 +02:00
LINE_PREFIX = "# [Nerd Fonts] "
2016-11-06 05:09:12 +02:00
2016-11-19 03:28:47 +02:00
cd $patched_parent_dir || {
2017-05-14 00:02:53 +02:00
echo >& 2 " $LINE_PREFIX Could not find patched fonts directory "
2016-11-06 05:09:12 +02:00
exit 1
}
2016-12-03 05:56:52 +02:00
function clear_file {
local outputfile = $1
2016-11-06 05:09:12 +02:00
# clear output file (needed for multiple runs or updates):
2018-01-13 04:05:05 +02:00
true > " $outputfile " 2> /dev/null
2016-12-03 05:56:52 +02:00
}
function write_header {
local outputfile = $1
2016-12-03 21:59:57 +02:00
local caskname = $2
2016-11-06 05:09:12 +02:00
{
2018-01-13 04:05:05 +02:00
printf "cask '%s' do\\n" " $caskname "
printf " version '%s'\\n" " $version "
printf " sha256 '%s'\\n\\n" " $sha256sum "
printf " url \"%s%s.zip\"\\n" " $downloadarchive " " $basename "
printf " appcast '%s',\\n" " $appcast "
printf " checkpoint: '%s'\\n" " $appcastcheckpoint "
2016-12-03 05:56:52 +02:00
} >> " $outputfile "
}
2016-11-06 05:09:12 +02:00
2016-12-03 05:56:52 +02:00
function write_body {
local outputfile = $1
shift;
local fonts = ( " $@ " )
2016-11-06 05:09:12 +02:00
2016-12-03 05:56:52 +02:00
if [ " ${ fonts [0] } " ] ;
2016-11-06 05:09:12 +02:00
then
2016-12-03 05:56:52 +02:00
for i in " ${ !fonts[@] } "
2016-11-06 05:09:12 +02:00
do
2016-12-03 05:56:52 +02:00
individualfont = $( basename " ${ fonts [ $i ] } " )
2016-11-19 03:28:47 +02:00
2018-01-13 04:05:05 +02:00
printf "## Found Font: %s\\n" " ${ fonts [ $i ] } "
2016-11-19 03:28:47 +02:00
2016-11-06 05:09:12 +02:00
if [ " $i " = = 0 ] ;
then
2016-12-03 05:56:52 +02:00
familyname = $( fc-query --format= '%{family}' " ${ fonts [ $i ] } " )
2016-11-13 19:22:10 +02:00
{
2018-01-13 04:05:05 +02:00
printf " name '%s (%s)'\\n" " $familyname " " $basename "
2016-11-13 19:22:10 +02:00
printf " homepage '%s'" " $homepage "
2018-01-13 04:05:05 +02:00
printf "\\n\\n"
2016-12-03 05:56:52 +02:00
} >> " $outputfile "
2016-11-06 05:09:12 +02:00
fi
2018-01-13 04:05:05 +02:00
printf " font '%s'\\n" " $individualfont " >> " $outputfile "
2016-11-06 05:09:12 +02:00
done
else
2017-05-14 00:02:53 +02:00
echo " $LINE_PREFIX Did not find TTF or OTF "
2016-11-06 05:09:12 +02:00
fi
2016-12-03 05:56:52 +02:00
}
function write_footer {
local outputfile = $1
2016-11-06 05:09:12 +02:00
{
2018-01-13 04:05:05 +02:00
printf "end\\n"
2016-12-03 05:56:52 +02:00
} >> " $outputfile "
}
2022-08-25 08:39:08 +02:00
pattern = $1
if [ " $pattern " = "" ] ; then
pattern = ".*"
fi
2016-12-03 21:59:57 +02:00
#find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
2016-12-03 05:56:52 +02:00
#find ./ProFont -maxdepth 2 -type d | # uncomment to test 1 font
2022-08-25 08:39:08 +02:00
find . -maxdepth 1 -mindepth 1 -type d -iregex " \./ $pattern " |
2016-12-03 05:56:52 +02:00
while read -r filename
do
dirname = $( dirname " $filename " )
basename = $( basename " $filename " )
sha256sum = $( sha256sum " ../archives/ ${ basename } .zip " | head -c 64)
searchdir = $filename
fontdir = $( basename " $( dirname " $dirname " ) " )
MONOFONTS = ( )
while IFS = read -d $'\0' -r file ; do
MONOFONTS = ( " ${ MONOFONTS [@] } " " $file " )
done < <( find " $searchdir " -type f -iwholename '*complete*' \( -iname '*.[o,t]tf' ! -wholename '*Windows*' -iname '*mono.*' \) -print0)
FONTS = ( )
while IFS = read -d $'\0' -r file ; do
FONTS = ( " ${ FONTS [@] } " " $file " )
done < <( find " $searchdir " -type f -iwholename '*complete*' \( -iname '*.[o,t]tf' ! -wholename '*Windows*' ! -iwholename '*mono.*' \) -print0)
outputdir = $PWD /../casks/
formattedbasename = $( echo " $basename " | tr "[:upper:]" "[:lower:]" )
2017-05-14 00:02:53 +02:00
echo " $LINE_PREFIX Generating cask for: $fontdir "
2016-12-03 05:56:52 +02:00
[ [ -d " $outputdir " ] ] || mkdir -p " $outputdir "
caskname = " font- $formattedbasename -nerd-font "
caskname_mono = " ${ caskname } -mono "
to = " $outputdir / ${ caskname } .rb "
to_mono = " $outputdir / ${ caskname_mono } .rb "
clear_file " $to "
2016-12-03 21:59:57 +02:00
write_header " $to " " $caskname "
2016-12-03 05:56:52 +02:00
clear_file " $to_mono "
2016-12-03 21:59:57 +02:00
write_header " $to_mono " " $caskname_mono "
2016-12-03 05:56:52 +02:00
write_body " $to " " ${ FONTS [@] } "
write_body " $to_mono " " ${ MONOFONTS [@] } "
write_footer " $to "
write_footer " $to_mono "
2016-11-06 05:09:12 +02:00
done
2016-12-03 05:56:52 +02:00