2018-07-09 16:20:40 +02:00
|
|
|
#!/usr/bin/env bash
|
2019-11-03 19:05:56 +02:00
|
|
|
# Nerd Fonts Version: 2.1.0
|
2018-03-11 04:39:34 +02:00
|
|
|
# Script Version: 1.1.1
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2020-04-12 12:51:29 +02:00
|
|
|
# used for debugging
|
|
|
|
# set -x
|
2016-11-21 02:32:03 +02:00
|
|
|
|
2017-07-30 03:21:11 +02:00
|
|
|
# for executing script to rebuild JUST the readmes:
|
|
|
|
# ./gotta-patch-em-all-font-patcher\!.sh "" info
|
2020-04-12 12:51:29 +02:00
|
|
|
# to test this script with a single font (pattern):
|
|
|
|
# ./gotta-patch-em-all-font-patcher\!.sh "iosevka" info
|
2017-07-30 03:21:11 +02:00
|
|
|
|
2017-05-14 00:02:53 +02:00
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
|
|
|
|
2016-10-29 22:45:55 +02:00
|
|
|
# Check for Fontforge
|
|
|
|
type fontforge >/dev/null 2>&1 || {
|
2017-05-14 00:02:53 +02:00
|
|
|
echo >&2 "$LINE_PREFIX FontForge must be installed before running this script."
|
2016-10-29 22:45:55 +02:00
|
|
|
echo >&2 "# Please see installation instructions at"
|
|
|
|
echo >&2 "# http://designwithfontforge.com/en-US/Installing_Fontforge.html"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
res1=$(date +%s)
|
|
|
|
parent_dir="${PWD}/../../"
|
|
|
|
# Set source and target directories
|
|
|
|
source_fonts_dir="${PWD}/../../src/unpatched-fonts"
|
|
|
|
like_pattern=''
|
2016-12-15 07:07:04 +02:00
|
|
|
complete_variations_per_family=4
|
|
|
|
font_typefaces_count=0
|
|
|
|
font_families_count=0
|
2016-10-29 22:45:55 +02:00
|
|
|
complete_variation_count=0
|
|
|
|
total_variation_count=0
|
|
|
|
total_count=0
|
|
|
|
last_parent_dir=""
|
|
|
|
unpatched_parent_dir="bin/scripts/../../src/unpatched-fonts"
|
|
|
|
patched_parent_dir="patched-fonts"
|
2016-11-07 00:04:53 +02:00
|
|
|
max_parallel_process=64
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2020-04-12 12:51:29 +02:00
|
|
|
if [ $# -eq 1 ] || [ "$1" != "" ]
|
2016-10-29 22:45:55 +02:00
|
|
|
then
|
|
|
|
like_pattern=$1
|
2017-05-14 00:02:53 +02:00
|
|
|
echo "$LINE_PREFIX Parameter given, limiting search and patch to pattern '$like_pattern' given"
|
2016-10-29 22:45:55 +02:00
|
|
|
fi
|
|
|
|
|
2016-11-21 02:32:03 +02:00
|
|
|
# simple second param option to allow to regenerate font info without re-patching
|
|
|
|
if [ $# -eq 2 ]
|
|
|
|
then
|
|
|
|
info_only=$2
|
2017-05-14 00:02:53 +02:00
|
|
|
echo "$LINE_PREFIX 'Info Only' Parameter given, only generating font info (not patching)"
|
2016-11-21 02:32:03 +02:00
|
|
|
fi
|
|
|
|
|
2016-10-29 22:45:55 +02:00
|
|
|
# correct way to output find results into an array (when files have space chars, etc)
|
2017-07-28 22:29:44 +02:00
|
|
|
# source: https://stackoverflow.com/questions/8213328/bash-script-find-output-to-array
|
2016-10-29 22:45:55 +02:00
|
|
|
source_fonts=()
|
|
|
|
while IFS= read -d $'\0' -r file ; do
|
|
|
|
source_fonts=("${source_fonts[@]}" "$file")
|
2018-03-11 04:39:34 +02:00
|
|
|
done < <(find "$source_fonts_dir" -iname "$like_pattern*.[o,t]tf" -type f -print0)
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
# print total number of source fonts found
|
2017-05-14 00:02:53 +02:00
|
|
|
echo "$LINE_PREFIX Total source fonts found: ${#source_fonts[*]}"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
function patch_font {
|
|
|
|
local f=$1; shift
|
2016-11-21 02:32:03 +02:00
|
|
|
local i=$1; shift
|
|
|
|
#echo $i
|
|
|
|
#echo $f
|
2016-11-01 04:01:00 +02:00
|
|
|
# take everything before the last slash (/) to start building the full path
|
2016-10-29 22:45:55 +02:00
|
|
|
local patched_font_dir="${f%/*}/"
|
|
|
|
# find replace unpatched parent dir with patched parent dir:
|
|
|
|
local patched_font_dir="${patched_font_dir/$unpatched_parent_dir/$patched_parent_dir}"
|
2016-11-01 04:01:00 +02:00
|
|
|
|
2016-10-29 22:45:55 +02:00
|
|
|
[[ -d "$patched_font_dir" ]] || mkdir -p "$patched_font_dir"
|
|
|
|
|
|
|
|
config_parent_dir=$( cd "$( dirname "$f" )" && cd ".." && pwd)
|
|
|
|
config_dir=$( cd "$( dirname "$f" )" && pwd)
|
|
|
|
|
|
|
|
# source the font config file if exists:
|
|
|
|
if [ -f "$config_dir/config.cfg" ]
|
|
|
|
then
|
2018-01-13 05:20:52 +02:00
|
|
|
# shellcheck source=/dev/null
|
2016-10-29 22:45:55 +02:00
|
|
|
source "$config_dir/config.cfg"
|
|
|
|
elif [ -f "$config_parent_dir/config.cfg" ]
|
|
|
|
then
|
2018-01-13 05:20:52 +02:00
|
|
|
# shellcheck source=/dev/null
|
2016-10-29 22:45:55 +02:00
|
|
|
source "$config_parent_dir/config.cfg"
|
|
|
|
fi
|
|
|
|
|
2018-02-26 04:52:36 +02:00
|
|
|
if [ -f "$config_parent_dir/config.json" ]
|
|
|
|
then
|
|
|
|
# load font configuration file and remove ligatures (for mono fonts):
|
|
|
|
font_config="--removeligatures --configfile $config_parent_dir/config.json"
|
|
|
|
else
|
|
|
|
font_config=""
|
|
|
|
fi
|
|
|
|
|
2016-12-15 04:50:36 +02:00
|
|
|
if [ "$post_process" ]
|
|
|
|
then
|
|
|
|
post_process="--postprocess=$post_process"
|
|
|
|
else
|
|
|
|
post_process=""
|
|
|
|
fi
|
|
|
|
|
2018-01-13 05:20:52 +02:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
# we know the '$config_has_powerline' is from the sourced file
|
2016-10-29 22:45:55 +02:00
|
|
|
if [ "$config_has_powerline" ]
|
|
|
|
then
|
|
|
|
powerline=""
|
2018-03-18 23:58:33 +02:00
|
|
|
combinations=$(printf "./font-patcher ${f##*/} %s\\n" {' --use-single-width-glyphs',}{' --windows',}{' --fontawesome',}{' --octicons',}{' --fontlinux',}{' --pomicons',}{' --powerlineextra',}{' --fontawesomeextension',}{' --powersymbols',}{' --weather',}{' --material',})
|
2016-10-29 22:45:55 +02:00
|
|
|
else
|
|
|
|
powerline="--powerline"
|
2018-03-18 23:58:33 +02:00
|
|
|
combinations=$(printf "./font-patcher ${f##*/} %s\\n" {' --powerline',}{' --use-single-width-glyphs',}{' --windows',}{' --fontawesome',}{' --octicons',}{' --fontlinux',}{' --pomicons',}{' --powerlineextra',}{' --fontawesomeextension',}{' --powersymbols',}{' --weather',}{' --material',})
|
2016-10-29 22:45:55 +02:00
|
|
|
fi
|
|
|
|
|
2016-11-06 18:29:35 +02:00
|
|
|
cd "$parent_dir" || {
|
|
|
|
echo >&2 "# Could not find project parent directory"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2016-12-15 04:50:36 +02:00
|
|
|
fontforge -quiet -script ./font-patcher "$f" -q $powerline $post_process --complete --no-progressbars --outputdir "${patched_font_dir}complete/" 2>/dev/null
|
2018-02-26 04:52:36 +02:00
|
|
|
fontforge -quiet -script ./font-patcher "$f" -q -s ${font_config} $powerline $post_process --complete --no-progressbars --outputdir "${patched_font_dir}complete/" 2>/dev/null
|
2016-12-15 04:50:36 +02:00
|
|
|
fontforge -quiet -script ./font-patcher "$f" -q -w $powerline $post_process --complete --no-progressbars --outputdir "${patched_font_dir}complete/" 2>/dev/null
|
2018-02-26 04:52:36 +02:00
|
|
|
fontforge -quiet -script ./font-patcher "$f" -q -s ${font_config} -w $powerline $post_process --complete --no-progressbars --outputdir "${patched_font_dir}complete/" 2>/dev/null
|
2016-11-06 18:29:35 +02:00
|
|
|
# wait for this group of background processes to finish to avoid forking too many processes
|
|
|
|
# that can add up quickly with the number of combinations
|
2016-10-29 22:45:55 +02:00
|
|
|
#wait
|
|
|
|
|
2016-11-21 02:32:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function generate_info {
|
|
|
|
local f=$1; shift
|
|
|
|
local i=$1; shift
|
|
|
|
#echo $i
|
|
|
|
#echo $f
|
|
|
|
# take everything before the last slash (/) to start building the full path
|
|
|
|
local patched_font_dir="${f%/*}/"
|
|
|
|
# find replace unpatched parent dir with patched parent dir:
|
|
|
|
local patched_font_dir="${patched_font_dir/$unpatched_parent_dir/$patched_parent_dir}"
|
|
|
|
|
|
|
|
[[ -d "$patched_font_dir" ]] || mkdir -p "$patched_font_dir"
|
|
|
|
|
|
|
|
config_parent_dir=$( cd "$( dirname "$f" )" && cd ".." && pwd)
|
|
|
|
config_dir=$( cd "$( dirname "$f" )" && pwd)
|
|
|
|
config_parent_dir_name=$(basename "$config_parent_dir")
|
|
|
|
is_unpatched_fonts_root=0
|
|
|
|
|
|
|
|
if [ "$config_parent_dir_name" == "unpatched-fonts" ]
|
|
|
|
then
|
|
|
|
is_unpatched_fonts_root=1
|
2016-12-15 07:07:04 +02:00
|
|
|
font_typefaces_count=$((font_typefaces_count+1))
|
2016-11-21 02:32:03 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# source the font config file if exists:
|
|
|
|
if [ -f "$config_dir/config.cfg" ]
|
|
|
|
then
|
2018-01-13 05:20:52 +02:00
|
|
|
# shellcheck source=/dev/null
|
2016-11-21 02:32:03 +02:00
|
|
|
source "$config_dir/config.cfg"
|
|
|
|
elif [ -f "$config_parent_dir/config.cfg" ]
|
|
|
|
then
|
2018-01-13 05:20:52 +02:00
|
|
|
# shellcheck source=/dev/null
|
2016-11-21 02:32:03 +02:00
|
|
|
source "$config_parent_dir/config.cfg"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$config_has_powerline" ]
|
|
|
|
then
|
|
|
|
powerline=""
|
2018-03-18 23:58:33 +02:00
|
|
|
combinations=$(printf "./font-patcher ${f##*/} %s\\n" {' --use-single-width-glyphs',}{' --windows',}{' --fontawesome',}{' --octicons',}{' --fontlinux',}{' --pomicons',}{' --powerlineextra',}{' --fontawesomeextension',}{' --powersymbols',}{' --weather',}{' --material',})
|
2016-11-21 02:32:03 +02:00
|
|
|
else
|
|
|
|
powerline="--powerline"
|
2018-03-18 23:58:33 +02:00
|
|
|
combinations=$(printf "./font-patcher ${f##*/} %s\\n" {' --powerline',}{' --use-single-width-glyphs',}{' --windows',}{' --fontawesome',}{' --octicons',}{' --fontlinux',}{' --pomicons',}{' --powerlineextra',}{' --fontawesomeextension',}{' --powersymbols',}{' --weather',}{' --material',})
|
2016-11-21 02:32:03 +02:00
|
|
|
fi
|
|
|
|
|
2016-12-15 07:07:04 +02:00
|
|
|
font_families_count=$((font_families_count+1))
|
|
|
|
complete_variation_count=$((complete_variation_count+complete_variations_per_family))
|
2016-10-29 22:45:55 +02:00
|
|
|
combination_count=$(printf "%s" "$combinations" | wc -l)
|
|
|
|
|
|
|
|
# generate the readmes:
|
|
|
|
|
|
|
|
# if first time with this font then re-build parent dir readme, else skip:
|
2017-07-23 17:28:10 +02:00
|
|
|
if [[ $config_parent_dir != "$last_parent_dir" ]] && [ $is_unpatched_fonts_root == "0" ];
|
2016-10-29 22:45:55 +02:00
|
|
|
then
|
2017-05-19 10:17:45 +02:00
|
|
|
echo "$LINE_PREFIX Re-generate parent directory readme"
|
2017-07-24 03:26:35 +02:00
|
|
|
generate_readme "$patched_font_dir.." 0
|
2016-10-29 22:45:55 +02:00
|
|
|
fi
|
|
|
|
|
2017-07-24 03:26:35 +02:00
|
|
|
generate_readme "$patched_font_dir" 1
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
last_parent_dir=$config_parent_dir
|
|
|
|
|
|
|
|
total_variation_count=$((total_variation_count+combination_count))
|
2016-12-15 07:07:04 +02:00
|
|
|
total_count=$((total_count+complete_variations_per_family+combination_count))
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Re-generate all the readmes
|
|
|
|
# $1 = fontdir path
|
|
|
|
function generate_readme {
|
2017-07-24 03:26:35 +02:00
|
|
|
local patched_font_dir=$1
|
|
|
|
local generate_combinations=$2
|
|
|
|
local combinations_filename="$patched_font_dir/readme.md"
|
|
|
|
local font_info="$patched_font_dir/font-info.md"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
# clear output file (needed for multiple runs or updates):
|
2018-01-13 05:20:52 +02:00
|
|
|
true > "$combinations_filename"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2016-11-01 04:01:00 +02:00
|
|
|
if [ -f "$font_info" ];
|
2016-10-29 22:45:55 +02:00
|
|
|
then
|
|
|
|
cat "$patched_font_dir/font-info.md" >> "$combinations_filename"
|
|
|
|
else
|
2017-05-14 00:02:53 +02:00
|
|
|
echo "$LINE_PREFIX Could not append font-info.md (file not found). Was standardize script run? It should be executed first"
|
2016-11-06 04:59:22 +02:00
|
|
|
echo "# looked for: $font_info"
|
2016-10-29 22:45:55 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
cat "$parent_dir/src/readme-per-directory-variations.md" >> "$combinations_filename"
|
|
|
|
|
2017-07-24 03:26:35 +02:00
|
|
|
if [ "$generate_combinations" == 1 ];
|
2017-07-23 17:28:10 +02:00
|
|
|
then
|
2017-07-24 03:26:35 +02:00
|
|
|
echo "$LINE_PREFIX Adding 'Possible Combinations' section"
|
2017-07-23 17:28:10 +02:00
|
|
|
# add to the file
|
|
|
|
{
|
|
|
|
printf "\`\`\`sh"
|
2018-01-13 05:20:52 +02:00
|
|
|
printf "\\n# %s Possible Combinations:\\n" "$combination_count"
|
|
|
|
printf "\\n"
|
2017-07-23 17:28:10 +02:00
|
|
|
printf "%s" "$combinations"
|
2018-01-13 05:20:52 +02:00
|
|
|
printf "\\n"
|
2017-07-23 17:28:10 +02:00
|
|
|
printf "\`\`\`"
|
|
|
|
} >> "$combinations_filename"
|
|
|
|
fi
|
2016-10-29 22:45:55 +02:00
|
|
|
}
|
|
|
|
|
2018-01-13 05:20:52 +02:00
|
|
|
if [ ! "$info_only" ]
|
2016-11-21 02:32:03 +02:00
|
|
|
then
|
|
|
|
# Iterate through source fonts
|
|
|
|
for i in "${!source_fonts[@]}"
|
|
|
|
do
|
|
|
|
patch_font "${source_fonts[$i]}" "$i" 2>/dev/null &
|
|
|
|
|
|
|
|
# un-comment to test this script (patch 1 font)
|
|
|
|
#break
|
|
|
|
|
|
|
|
# wait for this set of bg commands to finish: dont do too many at once!
|
|
|
|
# if we spawn a background process for each set of fonts it will
|
|
|
|
# end up using too many system resources
|
|
|
|
# however we want to run a certain number in parallel to decrease
|
|
|
|
# the amount of time patching all the fonts will take
|
|
|
|
# for now set a 'wait' for each X set of processes:
|
2018-01-13 05:20:52 +02:00
|
|
|
if [[ $((i % max_parallel_process)) == 0 ]];
|
2016-11-21 02:32:03 +02:00
|
|
|
then
|
2017-07-29 19:50:37 +02:00
|
|
|
echo "$LINE_PREFIX Complete Variation Count after max parallel process is $complete_variation_count"
|
2016-11-21 02:32:03 +02:00
|
|
|
wait
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# wait for all bg commands to finish
|
|
|
|
wait
|
|
|
|
fi
|
|
|
|
|
|
|
|
# update information in separate iteration (to avoid issues with bg processes and the counts):
|
2016-11-07 00:04:53 +02:00
|
|
|
# Iterate through source fonts
|
|
|
|
for i in "${!source_fonts[@]}"
|
2016-10-29 22:45:55 +02:00
|
|
|
do
|
2017-07-29 19:50:37 +02:00
|
|
|
# only output after last slash (/):
|
|
|
|
path=${source_fonts[$i]}
|
|
|
|
font_file=${path##*/}
|
|
|
|
echo "$LINE_PREFIX Generating info for '$font_file'"
|
|
|
|
generate_info "$path" "$i" 2>/dev/null
|
2016-10-29 22:45:55 +02:00
|
|
|
done
|
|
|
|
|
2017-08-20 19:55:36 +02:00
|
|
|
font_typefaces_count=$(find "${PWD}/../../${patched_parent_dir}/"* -maxdepth 0 -type d | wc -l)
|
|
|
|
|
2016-10-29 22:45:55 +02:00
|
|
|
res2=$(date +%s)
|
|
|
|
dt=$(echo "$res2 - $res1" | bc)
|
|
|
|
dd=$(echo "$dt/86400" | bc)
|
|
|
|
dt2=$(echo "$dt-86400*$dd" | bc)
|
|
|
|
dh=$(echo "$dt2/3600" | bc)
|
|
|
|
dt3=$(echo "$dt2-3600*$dh" | bc)
|
|
|
|
dm=$(echo "$dt3/60" | bc)
|
|
|
|
ds=$(echo "$dt3-60*$dm" | bc)
|
|
|
|
|
2018-01-13 05:20:52 +02:00
|
|
|
printf "$LINE_PREFIX Total runtime: %d:%02d:%02d:%02d\\n" "$dd" "$dh" "$dm" "$ds"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2018-01-13 05:20:52 +02:00
|
|
|
printf "# All fonts patched to sub-directories in \\t\\t\\t'%s'\\n" "$patched_parent_dir"
|
|
|
|
printf "# The total number of font typefaces patched was \\t\\t'%s'\\n" "$font_typefaces_count"
|
|
|
|
printf "# The total number of font families patched was \\t\\t'%s'\\n" "$font_families_count"
|
|
|
|
printf "# The total number of 'complete' patched fonts created was \\t'%s'\\n" "$complete_variation_count"
|
|
|
|
printf "# The total number of 'variation' patched fonts created was \\t'%s'\\n" "$total_variation_count"
|
|
|
|
printf "# The total number of patched fonts created was \\t\\t'%s'\\n" "$total_count"
|