From 5cda467ce34cb93df3d92d326462244d42ad63af Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Tue, 29 Nov 2022 11:50:19 +0100 Subject: [PATCH] casks: Improve cask names [why] Sometimes the shortest Family is not a meaningful name, for example iMWritingDuo iMWritingDuospace iMWritingMono iMWritingQuattro Obviously the shortest name is not adequate. [how] Instead we find the shortest word stem of the name. The common beginning of all names. In the example above that is `iMWriting`. If we have such a case we show in the name that there are multiple families in the cask, by adding "families" to the name. [note] Also always capitalize the font name. Some fonts have a all-small-letters name, but that seems a bit out of place and has been changed with the manual naming (previously) already to Capitalized Name. Signed-off-by: Fini Jastrow --- bin/scripts/generate-casks.sh | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/bin/scripts/generate-casks.sh b/bin/scripts/generate-casks.sh index 0b3c2dd4a..2b590d81e 100755 --- a/bin/scripts/generate-casks.sh +++ b/bin/scripts/generate-casks.sh @@ -61,6 +61,19 @@ function find_nerdish_family { 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 { local unpatchedname=$1 local outputfile=$2 @@ -80,17 +93,17 @@ function write_body { familyname=$(find_nerdish_family "${fonts[0]}") for i in "${!fonts[@]}"; do fn=$(find_nerdish_family "${fonts[$i]}") - if [ -z "${fn}" ]; then - break - fi - if [ "${#fn}" -lt "${#familyname}" ]; then - familyname=${fn} - fi + 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]}")