nerd-fonts/bin/scripts/generate-casks.sh

90 lines
2.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# version: 0.9.0
# 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
#set -x
patched_parent_dir="patched-fonts"
homepage="https://github.com/ryanoasis/nerd-fonts"
downloadroot="https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/patched-fonts/"
cd ../../patched-fonts/ || {
echo >&2 "# Could not find patched fonts directory"
exit 1
}
2016-11-06 17:21:25 +01:00
#find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
find . -maxdepth 1 -type d | # uncomment to test 1 font
while read -r filename
do
dirname=$(dirname "$filename")
basename=$(basename "$filename")
searchdir=$filename
fontdir=$(basename "$(dirname "$dirname")")
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*' \) -print0)
outputdir=$PWD/../casks/
formattedbasename=$(echo "$basename" | tr "[:upper:]" "[:lower:]")
echo "# Generating cask for: $fontdir"
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
caskname="font-$formattedbasename-nerd-font"
to="$outputdir/${caskname}.rb"
# clear output file (needed for multiple runs or updates):
> "$to" 2> /dev/null
# add to the file
{
printf "cask '%s' do\n" "$caskname"
printf " version :latest\n"
printf " sha256 :no_check\n\n"
printf " url '%s%s'\n" "$downloadroot" "$basename"
} >> "$to"
if [ "${FONTS[0]}" ];
then
#echo "fonts ${FONTS}"
#echo "fonts[0] ${FONTS[0]}"
for i in "${!FONTS[@]}"
do
echo "## Found Font"
individualfont=${FONTS[$i]}
downloadfont="${individualfont/$searchdir\//}"
echo "individualfont $individualfont"
echo "downloadfont $downloadfont"
echo "$i"
#echo "${FONTS[$i]}"
if [ "$i" == 0 ];
then
familyname=$(fc-query --format='%{family}' "${FONTS[$i]}")
printf " name '%s'\n" "$familyname" >> "$to"
printf " homepage '%s'" "$homepage" >> "$to"
printf "\n\n" >> "$to"
fi
printf " font '%s'\n" "$downloadfont" >> "$to"
done
else
echo "# Did not find TTF or OTF"
fi
# add to the file
{
printf "end"
} >> "$to"
done