2018-07-09 16:20:40 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-10-07 13:55:35 +02:00
|
|
|
# Nerd Fonts Version: 2.3.0-RC
|
2022-08-25 08:44:31 +02:00
|
|
|
# Script Version: 1.0.1
|
2016-11-06 04:09:12 +01: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 02:28:47 +01:00
|
|
|
#set -x
|
2022-11-25 14:12:47 +01:00
|
|
|
set -e
|
2016-11-06 04:09:12 +01:00
|
|
|
|
2022-10-07 13:55:35 +02:00
|
|
|
version="2.3.0-RC"
|
2016-11-19 02:28:47 +01:00
|
|
|
patched_parent_dir="../../patched-fonts/"
|
2016-11-06 04:09:12 +01:00
|
|
|
homepage="https://github.com/ryanoasis/nerd-fonts"
|
2016-11-13 18:22:10 +01:00
|
|
|
downloadarchive="https://github.com/ryanoasis/nerd-fonts/releases/download/v#{version}/"
|
2017-05-14 00:02:53 +02:00
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
2016-11-06 04:09:12 +01:00
|
|
|
|
2016-11-19 02:28:47 +01:00
|
|
|
cd $patched_parent_dir || {
|
2022-11-25 12:52:23 +01:00
|
|
|
echo >&2 "$LINE_PREFIX Could not find patched fonts directory"
|
|
|
|
exit 1
|
2016-11-06 04:09:12 +01:00
|
|
|
}
|
|
|
|
|
2016-12-03 04:56:52 +01:00
|
|
|
function clear_file {
|
2022-11-25 12:52:23 +01:00
|
|
|
local outputfile=$1
|
|
|
|
# clear output file (needed for multiple runs or updates):
|
|
|
|
true > "$outputfile" 2> /dev/null
|
2016-12-03 04:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function write_header {
|
2022-11-25 12:52:23 +01:00
|
|
|
local outputfile=$1
|
|
|
|
local caskname=$2
|
|
|
|
|
|
|
|
{
|
|
|
|
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"
|
|
|
|
} >> "$outputfile"
|
2016-12-03 04:56:52 +01:00
|
|
|
}
|
2016-11-06 04:09:12 +01:00
|
|
|
|
2016-12-03 04:56:52 +01:00
|
|
|
function write_body {
|
2022-11-25 12:52:23 +01:00
|
|
|
local outputfile=$1
|
|
|
|
shift;
|
|
|
|
local fonts=("$@")
|
|
|
|
|
|
|
|
if [ "${fonts[0]}" ]; then
|
2022-11-25 15:02:21 +01:00
|
|
|
longest=-1
|
|
|
|
# Find longest filename for pretty printing
|
|
|
|
for i in "${!fonts[@]}"; do
|
|
|
|
basename=$(basename "${fonts[$i]}")
|
|
|
|
if [ ${#basename} -gt $longest ]; then
|
|
|
|
longest=${#basename}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# Process font files
|
2022-11-25 12:52:23 +01:00
|
|
|
for i in "${!fonts[@]}"; do
|
|
|
|
individualfont=$(basename "${fonts[$i]}")
|
2022-11-25 15:02:21 +01:00
|
|
|
individualdir=$(dirname "${fonts[$i]}")
|
2022-11-25 12:52:23 +01:00
|
|
|
|
2022-11-25 15:02:21 +01:00
|
|
|
printf " %-${longest}s %s\\n" "${individualfont}" "${individualdir}"
|
2022-11-25 12:52:23 +01:00
|
|
|
|
|
|
|
if [ "$i" == 0 ]; then
|
|
|
|
familyname=$(fc-query --format='%{family}' "${fonts[$i]}")
|
|
|
|
{
|
|
|
|
printf " name \"%s (%s)\"\\n" "$familyname" "$basename"
|
2022-11-25 14:12:47 +01:00
|
|
|
printf " desc \"Developer targeted fonts with a high number of glyphs\"\\n"
|
2022-11-25 12:52:23 +01:00
|
|
|
printf " homepage \"%s\"" "$homepage"
|
|
|
|
printf "\\n\\n"
|
2022-11-25 14:12:47 +01:00
|
|
|
printf " livecheck do\\n"
|
|
|
|
printf " url :url\\n"
|
|
|
|
printf " strategy :github_latest\\n"
|
|
|
|
printf " end\\n\\n"
|
2022-11-25 12:52:23 +01:00
|
|
|
} >> "$outputfile"
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf " font \"%s\"\\n" "$individualfont" >> "$outputfile"
|
|
|
|
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "$LINE_PREFIX Did not find TTF or OTF"
|
|
|
|
fi
|
2016-12-03 04:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function write_footer {
|
2022-11-25 12:52:23 +01:00
|
|
|
local outputfile=$1
|
2016-11-06 04:09:12 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
{
|
|
|
|
printf "end\\n"
|
|
|
|
} >> "$outputfile"
|
2016-12-03 04:56:52 +01:00
|
|
|
}
|
|
|
|
|
2022-08-25 08:39:08 +02:00
|
|
|
pattern=$1
|
|
|
|
if [ "$pattern" = "" ]; then
|
2022-11-25 12:52:23 +01:00
|
|
|
pattern=".*"
|
2022-08-25 08:39:08 +02:00
|
|
|
fi
|
|
|
|
|
2016-12-03 20:59:57 +01:00
|
|
|
#find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
|
2016-12-03 04:56:52 +01:00
|
|
|
#find ./ProFont -maxdepth 2 -type d | # uncomment to test 1 font
|
2022-11-25 14:12:47 +01:00
|
|
|
find . -maxdepth 1 -mindepth 1 -type d -iregex "\./$pattern" | sort |
|
2022-11-25 12:52:23 +01:00
|
|
|
while read -r filename; do
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
dirname=$(dirname "$filename")
|
|
|
|
basename=$(basename "$filename")
|
2022-11-25 14:12:47 +01:00
|
|
|
if [ ! -f "../archives/${basename}.zip" ]; then
|
|
|
|
echo "${LINE_PREFIX} No archive for: ${basename}, skipping..."
|
|
|
|
continue
|
|
|
|
fi
|
2022-11-25 12:52:23 +01:00
|
|
|
sha256sum=$(sha256sum "../archives/${basename}.zip" | head -c 64)
|
|
|
|
searchdir=$filename
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
MONOFONTS=()
|
|
|
|
while IFS= read -d $'\0' -r file; do
|
|
|
|
MONOFONTS=("${MONOFONTS[@]}" "$file")
|
2022-11-25 15:02:21 +01:00
|
|
|
done < <(find "$searchdir" -type f -iwholename '*complete*' \( -iname '*.[o,t]tf' ! -wholename '*Windows*' -iname '*complete mono*' \) -print0 | sort -z)
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
FONTS=()
|
|
|
|
while IFS= read -d $'\0' -r file; do
|
|
|
|
FONTS=("${FONTS[@]}" "$file")
|
2022-11-25 15:02:21 +01:00
|
|
|
done < <(find "$searchdir" -type f -iwholename '*complete*' \( -iname '*.[o,t]tf' ! -wholename '*Windows*' ! -iname '*complete mono*' \) -print0 | sort -z)
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
outputdir=$PWD/../casks
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
formattedbasename=$(echo "$basename" | tr "[:upper:]" "[:lower:]")
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
echo "$LINE_PREFIX Generating cask for: $basename"
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
caskname="font-$formattedbasename-nerd-font"
|
|
|
|
caskname_mono="${caskname}-mono"
|
|
|
|
to="$outputdir/${caskname}.rb"
|
|
|
|
to_mono="$outputdir/${caskname_mono}.rb"
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
clear_file "$to"
|
|
|
|
write_header "$to" "$caskname"
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
clear_file "$to_mono"
|
|
|
|
write_header "$to_mono" "$caskname_mono"
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
write_body "$to" "${FONTS[@]}"
|
|
|
|
write_body "$to_mono" "${MONOFONTS[@]}"
|
2016-12-03 04:56:52 +01:00
|
|
|
|
2022-11-25 12:52:23 +01:00
|
|
|
write_footer "$to"
|
|
|
|
write_footer "$to_mono"
|
2022-08-30 10:18:42 +02:00
|
|
|
|
2022-11-25 15:02:21 +01:00
|
|
|
echo "## Created casks: $(realpath ${outputdir}/${caskname})*.rb"
|
2016-11-06 04:09:12 +01:00
|
|
|
done
|