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

189 lines
6 KiB
Bash
Raw Normal View History

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
# Script Version: 2.0.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
# * Needs the zip archives in archives/ (i.e. run `./archive-fonts.sh` first)
#
# [1] Accepts one parameter, a pattern which fonts to examine, if not given defaults
# to "*" which is all fonts. Example `./generate-casks.sh 'Hasklig'`
#set -x
set -e
2022-10-07 13:55:35 +02:00
version="2.3.0-RC"
homepage="https://github.com/ryanoasis/nerd-fonts"
downloadarchive="https://github.com/ryanoasis/nerd-fonts/releases/download/v#{version}/"
2017-05-14 00:02:53 +02:00
LINE_PREFIX="# [Nerd Fonts] "
casks: Add unpatched fontname in cask description [why] People might want to know how the original/unpatched font really is called. This is done for most current casks. [how] Utilize jq and the fonts.json database to retrieve the name (which is stored nowhere else). Put it in the parens in the name field. Update some `unpatchedName`s. [note] Examples from current casks: homebrew-cask-fonts/Casks$ find . -name '*nerd-font*' -exec grep " name" {} \; | sort name "3270 Nerd Font (3270)" name "Agave Nerd Font (Agave)" name "Anonymice Nerd Font (Anonymous Pro)" name "Arimo Nerd Font (Arimo)" name "AurulentSansMono Nerd Font (Aurulent Sans Mono)" name "BigBlue_Terminal Nerd Font families (BigBlue Terminal)" name "BitstreamVeraSansMono Nerd Font (Bitstream Vera Sans Mono)" name "BlexMono Nerd Font (IBM Plex Mono)" name "CaskaydiaCove Nerd Font (Caskaydia code)" name "CodeNewRoman Nerd Font (Code New Roman)" name "Cousine Nerd Font (Cousine)" name "DaddyTimeMono Nerd Font (DaddyTimeMono)" name "DejaVuSansMono Nerd Font (DejaVu Sans Mono)" name "DroidSansMono Nerd Font (Droid Sans Mono)" name "FantasqueSansMono Nerd Font (Fantasque Sans Mono)" name "FiraCode Nerd Font (Fira Code)" name "FiraMono Nerd Font (Fira)" name "GohuFont Nerd Font (Gohu)" name "GoMono Nerd Font (Go)" name "Hack Nerd Font (Hack)" name "Hasklug Nerd Font (Hasklig)" name "HeavyData Nerd Font (Heavy Data)" name "Hurmit Nerd Font (Hermit)" name "iMWriting Nerd Font families (iA Writer)" name "InconsolataGo Nerd Font (Inconsolata Go)" name "InconsolataLGC Nerd Font (Inconsolata LGC)" name "Inconsolata Nerd Font (Inconsolata)" name "Iosevka Nerd Font (Iosevka)" name "JetBrainsMono Nerd Font (JetBrains Mono)" name "Lekton Nerd Font (Lekton)" name "Literation Nerd Font families (Liberation)" name "MesloLG Nerd Font families (Meslo LG)" name "Monofur Nerd Font (Monofur)" name "Monoid Nerd Font (Monoid)" name "Mononoki Nerd Font (Mononoki)" name "mplus Nerd Font (M+)" name "Nerd Font Symbols Template (Symbols Only)" name "Noto Nerd Font families (Noto)" name "OpenDyslexic Nerd Font families (OpenDyslexic)" name "Overpass Nerd Font (Overpass)" name "ProFont Nerd Font families (ProFont)" name "ProggyCleanTT Nerd Font families (ProggyCleanTT)" name "RobotoMono Nerd Font (RobotoMono)" name "SauceCodePro Nerd Font (Source Code Pro)" name "ShureTechMono Nerd Font (Share Tech Mono)" name "SpaceMono Nerd Font (Space Mono)" name "TerminessTTF Nerd Font (Terminus)" name "Tinos Nerd Font (Tinos)" name "UbuntuMono Nerd Font (Ubuntu Mono)" name "Ubuntu Nerd Font (Ubuntu)" name "VictorMono Nerd Font (Victor Mono)" Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-11-25 16:47:12 +01:00
scripts_root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/"
patched_parent_dir="${scripts_root_dir}/../../patched-fonts/"
cd $patched_parent_dir || {
echo >&2 "$LINE_PREFIX Could not find patched fonts directory"
exit 1
}
function clear_file {
local outputfile=$1
# clear output file (needed for multiple runs or updates):
true > "$outputfile" 2> /dev/null
}
function write_header {
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"
}
# Query all Family names of a font individually and return the first
# we found that has "Nerd" in it. We need this because some fonts have
# broken Family names.
function find_nerdish_family {
local fontfile=$1
local idx=0
while :; do
local fn=$(fc-query --format="%{family[${idx}]}" "${fontfile}")
if [ -z "$fn" ]; then
return
fi
if [[ "${fn}" == *Nerd* ]]; then
echo "${fn}"
return
fi
idx=$((${idx} + 1))
done
}
# Return the longest common starting part of two strings
# This is the stem, the basic base name of the fonts
function find_common_stem {
local first=$1
local second=$2
for i in $(seq ${#first} -1 1); do
if [ "${first:0:$i}" == "${second:0:$i}" ]; then
echo "${first:0:$i}"
return
fi
done
}
function write_body {
casks: Add unpatched fontname in cask description [why] People might want to know how the original/unpatched font really is called. This is done for most current casks. [how] Utilize jq and the fonts.json database to retrieve the name (which is stored nowhere else). Put it in the parens in the name field. Update some `unpatchedName`s. [note] Examples from current casks: homebrew-cask-fonts/Casks$ find . -name '*nerd-font*' -exec grep " name" {} \; | sort name "3270 Nerd Font (3270)" name "Agave Nerd Font (Agave)" name "Anonymice Nerd Font (Anonymous Pro)" name "Arimo Nerd Font (Arimo)" name "AurulentSansMono Nerd Font (Aurulent Sans Mono)" name "BigBlue_Terminal Nerd Font families (BigBlue Terminal)" name "BitstreamVeraSansMono Nerd Font (Bitstream Vera Sans Mono)" name "BlexMono Nerd Font (IBM Plex Mono)" name "CaskaydiaCove Nerd Font (Caskaydia code)" name "CodeNewRoman Nerd Font (Code New Roman)" name "Cousine Nerd Font (Cousine)" name "DaddyTimeMono Nerd Font (DaddyTimeMono)" name "DejaVuSansMono Nerd Font (DejaVu Sans Mono)" name "DroidSansMono Nerd Font (Droid Sans Mono)" name "FantasqueSansMono Nerd Font (Fantasque Sans Mono)" name "FiraCode Nerd Font (Fira Code)" name "FiraMono Nerd Font (Fira)" name "GohuFont Nerd Font (Gohu)" name "GoMono Nerd Font (Go)" name "Hack Nerd Font (Hack)" name "Hasklug Nerd Font (Hasklig)" name "HeavyData Nerd Font (Heavy Data)" name "Hurmit Nerd Font (Hermit)" name "iMWriting Nerd Font families (iA Writer)" name "InconsolataGo Nerd Font (Inconsolata Go)" name "InconsolataLGC Nerd Font (Inconsolata LGC)" name "Inconsolata Nerd Font (Inconsolata)" name "Iosevka Nerd Font (Iosevka)" name "JetBrainsMono Nerd Font (JetBrains Mono)" name "Lekton Nerd Font (Lekton)" name "Literation Nerd Font families (Liberation)" name "MesloLG Nerd Font families (Meslo LG)" name "Monofur Nerd Font (Monofur)" name "Monoid Nerd Font (Monoid)" name "Mononoki Nerd Font (Mononoki)" name "mplus Nerd Font (M+)" name "Nerd Font Symbols Template (Symbols Only)" name "Noto Nerd Font families (Noto)" name "OpenDyslexic Nerd Font families (OpenDyslexic)" name "Overpass Nerd Font (Overpass)" name "ProFont Nerd Font families (ProFont)" name "ProggyCleanTT Nerd Font families (ProggyCleanTT)" name "RobotoMono Nerd Font (RobotoMono)" name "SauceCodePro Nerd Font (Source Code Pro)" name "ShureTechMono Nerd Font (Share Tech Mono)" name "SpaceMono Nerd Font (Space Mono)" name "TerminessTTF Nerd Font (Terminus)" name "Tinos Nerd Font (Tinos)" name "UbuntuMono Nerd Font (Ubuntu Mono)" name "Ubuntu Nerd Font (Ubuntu)" name "VictorMono Nerd Font (Victor Mono)" Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-11-25 16:47:12 +01:00
local unpatchedname=$1
local outputfile=$2
shift; shift;
local fonts=("$@")
if [ "${fonts[0]}" ]; then
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
# Find familyname of non Mono variant (well, rather shortest because we can contain multiple families)
familyname=$(find_nerdish_family "${fonts[0]}")
for i in "${!fonts[@]}"; do
fn=$(find_nerdish_family "${fonts[$i]}")
familyname=$(find_common_stem "${fn}" "${familyname}")
done
if [ -z "${familyname}" ]; then
echo >&2 "${LINE_PREFIX} Can not determine family name"
exit 2
fi
# Family names differ in front of "Nerd Font" (stem is short)
if [[ "${familyname}" != *Nerd* ]]; then
familyname="${familyname} Nerd Font families"
fi
familyname="$(tr [:lower:] [:upper:] <<< ${familyname:0:1})${familyname:1}"
# Process font files
for i in "${!fonts[@]}"; do
individualfont=$(basename "${fonts[$i]}")
individualdir=$(dirname "${fonts[$i]}")
printf " %-${longest}s %s\\n" "${individualfont}" "${individualdir}"
if [ "$i" == 0 ]; then
{
casks: Add unpatched fontname in cask description [why] People might want to know how the original/unpatched font really is called. This is done for most current casks. [how] Utilize jq and the fonts.json database to retrieve the name (which is stored nowhere else). Put it in the parens in the name field. Update some `unpatchedName`s. [note] Examples from current casks: homebrew-cask-fonts/Casks$ find . -name '*nerd-font*' -exec grep " name" {} \; | sort name "3270 Nerd Font (3270)" name "Agave Nerd Font (Agave)" name "Anonymice Nerd Font (Anonymous Pro)" name "Arimo Nerd Font (Arimo)" name "AurulentSansMono Nerd Font (Aurulent Sans Mono)" name "BigBlue_Terminal Nerd Font families (BigBlue Terminal)" name "BitstreamVeraSansMono Nerd Font (Bitstream Vera Sans Mono)" name "BlexMono Nerd Font (IBM Plex Mono)" name "CaskaydiaCove Nerd Font (Caskaydia code)" name "CodeNewRoman Nerd Font (Code New Roman)" name "Cousine Nerd Font (Cousine)" name "DaddyTimeMono Nerd Font (DaddyTimeMono)" name "DejaVuSansMono Nerd Font (DejaVu Sans Mono)" name "DroidSansMono Nerd Font (Droid Sans Mono)" name "FantasqueSansMono Nerd Font (Fantasque Sans Mono)" name "FiraCode Nerd Font (Fira Code)" name "FiraMono Nerd Font (Fira)" name "GohuFont Nerd Font (Gohu)" name "GoMono Nerd Font (Go)" name "Hack Nerd Font (Hack)" name "Hasklug Nerd Font (Hasklig)" name "HeavyData Nerd Font (Heavy Data)" name "Hurmit Nerd Font (Hermit)" name "iMWriting Nerd Font families (iA Writer)" name "InconsolataGo Nerd Font (Inconsolata Go)" name "InconsolataLGC Nerd Font (Inconsolata LGC)" name "Inconsolata Nerd Font (Inconsolata)" name "Iosevka Nerd Font (Iosevka)" name "JetBrainsMono Nerd Font (JetBrains Mono)" name "Lekton Nerd Font (Lekton)" name "Literation Nerd Font families (Liberation)" name "MesloLG Nerd Font families (Meslo LG)" name "Monofur Nerd Font (Monofur)" name "Monoid Nerd Font (Monoid)" name "Mononoki Nerd Font (Mononoki)" name "mplus Nerd Font (M+)" name "Nerd Font Symbols Template (Symbols Only)" name "Noto Nerd Font families (Noto)" name "OpenDyslexic Nerd Font families (OpenDyslexic)" name "Overpass Nerd Font (Overpass)" name "ProFont Nerd Font families (ProFont)" name "ProggyCleanTT Nerd Font families (ProggyCleanTT)" name "RobotoMono Nerd Font (RobotoMono)" name "SauceCodePro Nerd Font (Source Code Pro)" name "ShureTechMono Nerd Font (Share Tech Mono)" name "SpaceMono Nerd Font (Space Mono)" name "TerminessTTF Nerd Font (Terminus)" name "Tinos Nerd Font (Tinos)" name "UbuntuMono Nerd Font (Ubuntu Mono)" name "Ubuntu Nerd Font (Ubuntu)" name "VictorMono Nerd Font (Victor Mono)" Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-11-25 16:47:12 +01:00
printf " name \"%s (%s)\"\\n" "$familyname" "$unpatchedname"
printf " desc \"Developer targeted fonts with a high number of glyphs\"\\n"
printf " homepage \"%s\"" "$homepage"
printf "\\n\\n"
printf " livecheck do\\n"
printf " url :url\\n"
printf " strategy :github_latest\\n"
printf " end\\n\\n"
} >> "$outputfile"
fi
printf " font \"%s\"\\n" "$individualfont" >> "$outputfile"
done
else
echo "$LINE_PREFIX Did not find TTF or OTF"
fi
}
function write_footer {
local outputfile=$1
{
printf "end\\n"
} >> "$outputfile"
}
pattern=$1
if [ "$pattern" = "" ]; then
pattern=".*"
fi
find . -maxdepth 1 -mindepth 1 -type d -iregex "\./$pattern" | sort |
while read -r filename; do
dirname=$(dirname "$filename")
basename=$(basename "$filename")
if [ ! -f "../archives/${basename}.zip" ]; then
echo "${LINE_PREFIX} No archive for: ${basename}, skipping..."
continue
fi
sha256sum=$(sha256sum "../archives/${basename}.zip" | head -c 64)
searchdir=$filename
originalname=$(cat "${scripts_root_dir}/lib/fonts.json" | jq -r ".fonts[] | select(.folderName == "\"${basename}\"") | .unpatchedName" "${scripts_root_dir}/lib/fonts.json" | head -n 1)
caskbasename=$(cat "${scripts_root_dir}/lib/fonts.json" | jq -r ".fonts[] | select(.folderName == "\"${basename}\"") | .caskName" "${scripts_root_dir}/lib/fonts.json" | head -n 1)
casks: Add unpatched fontname in cask description [why] People might want to know how the original/unpatched font really is called. This is done for most current casks. [how] Utilize jq and the fonts.json database to retrieve the name (which is stored nowhere else). Put it in the parens in the name field. Update some `unpatchedName`s. [note] Examples from current casks: homebrew-cask-fonts/Casks$ find . -name '*nerd-font*' -exec grep " name" {} \; | sort name "3270 Nerd Font (3270)" name "Agave Nerd Font (Agave)" name "Anonymice Nerd Font (Anonymous Pro)" name "Arimo Nerd Font (Arimo)" name "AurulentSansMono Nerd Font (Aurulent Sans Mono)" name "BigBlue_Terminal Nerd Font families (BigBlue Terminal)" name "BitstreamVeraSansMono Nerd Font (Bitstream Vera Sans Mono)" name "BlexMono Nerd Font (IBM Plex Mono)" name "CaskaydiaCove Nerd Font (Caskaydia code)" name "CodeNewRoman Nerd Font (Code New Roman)" name "Cousine Nerd Font (Cousine)" name "DaddyTimeMono Nerd Font (DaddyTimeMono)" name "DejaVuSansMono Nerd Font (DejaVu Sans Mono)" name "DroidSansMono Nerd Font (Droid Sans Mono)" name "FantasqueSansMono Nerd Font (Fantasque Sans Mono)" name "FiraCode Nerd Font (Fira Code)" name "FiraMono Nerd Font (Fira)" name "GohuFont Nerd Font (Gohu)" name "GoMono Nerd Font (Go)" name "Hack Nerd Font (Hack)" name "Hasklug Nerd Font (Hasklig)" name "HeavyData Nerd Font (Heavy Data)" name "Hurmit Nerd Font (Hermit)" name "iMWriting Nerd Font families (iA Writer)" name "InconsolataGo Nerd Font (Inconsolata Go)" name "InconsolataLGC Nerd Font (Inconsolata LGC)" name "Inconsolata Nerd Font (Inconsolata)" name "Iosevka Nerd Font (Iosevka)" name "JetBrainsMono Nerd Font (JetBrains Mono)" name "Lekton Nerd Font (Lekton)" name "Literation Nerd Font families (Liberation)" name "MesloLG Nerd Font families (Meslo LG)" name "Monofur Nerd Font (Monofur)" name "Monoid Nerd Font (Monoid)" name "Mononoki Nerd Font (Mononoki)" name "mplus Nerd Font (M+)" name "Nerd Font Symbols Template (Symbols Only)" name "Noto Nerd Font families (Noto)" name "OpenDyslexic Nerd Font families (OpenDyslexic)" name "Overpass Nerd Font (Overpass)" name "ProFont Nerd Font families (ProFont)" name "ProggyCleanTT Nerd Font families (ProggyCleanTT)" name "RobotoMono Nerd Font (RobotoMono)" name "SauceCodePro Nerd Font (Source Code Pro)" name "ShureTechMono Nerd Font (Share Tech Mono)" name "SpaceMono Nerd Font (Space Mono)" name "TerminessTTF Nerd Font (Terminus)" name "Tinos Nerd Font (Tinos)" name "UbuntuMono Nerd Font (Ubuntu Mono)" name "Ubuntu Nerd Font (Ubuntu)" name "VictorMono Nerd Font (Victor Mono)" Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-11-25 16:47:12 +01:00
if [ -z "$originalname" ]; then
echo "${LINE_PREFIX} Can not find ${basename} in fonts.json, skipping..."
continue
fi
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 Compatible*' \) -print0 | sort -z)
outputdir=$PWD/../casks
echo "$LINE_PREFIX Generating cask for: $basename"
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
caskname="font-${caskbasename}-nerd-font"
to="$outputdir/${caskname}.rb"
echo "@@@$caskname@@@"
clear_file "$to"
write_header "$to" "$caskname"
casks: Add unpatched fontname in cask description [why] People might want to know how the original/unpatched font really is called. This is done for most current casks. [how] Utilize jq and the fonts.json database to retrieve the name (which is stored nowhere else). Put it in the parens in the name field. Update some `unpatchedName`s. [note] Examples from current casks: homebrew-cask-fonts/Casks$ find . -name '*nerd-font*' -exec grep " name" {} \; | sort name "3270 Nerd Font (3270)" name "Agave Nerd Font (Agave)" name "Anonymice Nerd Font (Anonymous Pro)" name "Arimo Nerd Font (Arimo)" name "AurulentSansMono Nerd Font (Aurulent Sans Mono)" name "BigBlue_Terminal Nerd Font families (BigBlue Terminal)" name "BitstreamVeraSansMono Nerd Font (Bitstream Vera Sans Mono)" name "BlexMono Nerd Font (IBM Plex Mono)" name "CaskaydiaCove Nerd Font (Caskaydia code)" name "CodeNewRoman Nerd Font (Code New Roman)" name "Cousine Nerd Font (Cousine)" name "DaddyTimeMono Nerd Font (DaddyTimeMono)" name "DejaVuSansMono Nerd Font (DejaVu Sans Mono)" name "DroidSansMono Nerd Font (Droid Sans Mono)" name "FantasqueSansMono Nerd Font (Fantasque Sans Mono)" name "FiraCode Nerd Font (Fira Code)" name "FiraMono Nerd Font (Fira)" name "GohuFont Nerd Font (Gohu)" name "GoMono Nerd Font (Go)" name "Hack Nerd Font (Hack)" name "Hasklug Nerd Font (Hasklig)" name "HeavyData Nerd Font (Heavy Data)" name "Hurmit Nerd Font (Hermit)" name "iMWriting Nerd Font families (iA Writer)" name "InconsolataGo Nerd Font (Inconsolata Go)" name "InconsolataLGC Nerd Font (Inconsolata LGC)" name "Inconsolata Nerd Font (Inconsolata)" name "Iosevka Nerd Font (Iosevka)" name "JetBrainsMono Nerd Font (JetBrains Mono)" name "Lekton Nerd Font (Lekton)" name "Literation Nerd Font families (Liberation)" name "MesloLG Nerd Font families (Meslo LG)" name "Monofur Nerd Font (Monofur)" name "Monoid Nerd Font (Monoid)" name "Mononoki Nerd Font (Mononoki)" name "mplus Nerd Font (M+)" name "Nerd Font Symbols Template (Symbols Only)" name "Noto Nerd Font families (Noto)" name "OpenDyslexic Nerd Font families (OpenDyslexic)" name "Overpass Nerd Font (Overpass)" name "ProFont Nerd Font families (ProFont)" name "ProggyCleanTT Nerd Font families (ProggyCleanTT)" name "RobotoMono Nerd Font (RobotoMono)" name "SauceCodePro Nerd Font (Source Code Pro)" name "ShureTechMono Nerd Font (Share Tech Mono)" name "SpaceMono Nerd Font (Space Mono)" name "TerminessTTF Nerd Font (Terminus)" name "Tinos Nerd Font (Tinos)" name "UbuntuMono Nerd Font (Ubuntu Mono)" name "Ubuntu Nerd Font (Ubuntu)" name "VictorMono Nerd Font (Victor Mono)" Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-11-25 16:47:12 +01:00
write_body "$originalname" "$to" "${FONTS[@]}"
write_footer "$to"
echo "## Created casks: $(realpath ${to})"
done