From 7bc729e27a3d73f6372323d09339f1846cf60435 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Fri, 22 Apr 2022 13:32:30 +0200 Subject: [PATCH] gotta-patch-em-all: Allow to specify directory filter [why] We can limit the font files to patch with the gotta-patch-em-all script to some specific file names; the case insensitive beginning of the basename of the font file, to be specific. Sometimes we do not know how the actual font files are named, we just know the directory name. [how] The old filter checked for the beginning of a file name, so we keep this behavior and allow to check for the beginning of a directory name. As differentiator the first character of the passed filter is used. As a slash is not allowed in the file name filters: If the first char is a slash, we search for font files in a directory that begins with that name. The file name is not considered in this case. Examples: gotta-patch-em-all-font-patcher!.sh Fira Patches all font files that begin (case insensitive) with 'fira'. It must be the basename of the font file, the path to the file is not considered. (Old behavior.) Translated to a glob this is roughly **/Fira*.[ot]tf gotta-patch-em-all-font-patcher!.sh /Fira Patches all font files that are in directories that begin (case insensitive) with 'fira'. It can not be the beginning of the font file basename. Translated to a glob this is roughly **/Fira*/**/*.[ot]tf Signed-off-by: Fini Jastrow --- .../gotta-patch-em-all-font-patcher!.sh | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/scripts/gotta-patch-em-all-font-patcher!.sh b/bin/scripts/gotta-patch-em-all-font-patcher!.sh index 7a37e8881..719998f3c 100755 --- a/bin/scripts/gotta-patch-em-all-font-patcher!.sh +++ b/bin/scripts/gotta-patch-em-all-font-patcher!.sh @@ -5,6 +5,16 @@ # used for debugging # set -x +# The optional first argument to this script is a filter for the fonts to patch. +# All font files that start with that filter (and are ttf or otf files) will +# be processed only. +# Example ./gotta-patch-em-all-font-patcher\!.sh "iosevka" +# Process all font files that start with "iosevka" +# If the argument starts with a '/' all font files in a directory that matches +# the filter are processed only. +# Example ./gotta-patch-em-all-font-patcher\!.sh "/iosevka" +# Process all font files that are in directories that start with "iosevka" + # for executing script to rebuild JUST the readmes: # ./gotta-patch-em-all-font-patcher\!.sh "" info # to test this script with a single font (pattern): @@ -40,9 +50,15 @@ patched_parent_dir="patched-fonts" max_parallel_process=64 if [ $# -eq 1 ] || [ "$1" != "" ] +then + if [[ "${1:0:1}" == "/" ]] then - like_pattern=$1 - echo "$LINE_PREFIX Parameter given, limiting search and patch to pattern '$like_pattern' given" + like_pattern="-ipath \"*$1*/*.[o,t]tf\"" + echo "$LINE_PREFIX Parameter given, limiting search and patch to pathname pattern '$1' given" + else + like_pattern="-iname \"$1*.[o,t]tf\"" + echo "$LINE_PREFIX Parameter given, limiting search and patch to filename pattern '$1' given" + fi fi # simple second param option to allow to regenerate font info without re-patching @@ -57,7 +73,7 @@ fi source_fonts=() while IFS= read -d $'\0' -r file ; do source_fonts=("${source_fonts[@]}" "$file") -done < <(find "$source_fonts_dir" -iname "$like_pattern*.[o,t]tf" -type f -print0) +done < <(find "$source_fonts_dir" ${like_pattern} -type f -print0) # print total number of source fonts found echo "$LINE_PREFIX Total source fonts found: ${#source_fonts[*]}"