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-03 21:14:22 +02:00
|
|
|
# Script Version: 1.0.0
|
2016-11-30 05:48:54 +02:00
|
|
|
# Iterates over all patched fonts directories
|
|
|
|
# to generate a fontconfig based on the Nerd Fonts Symbols font
|
|
|
|
# that contains only the glyphs
|
|
|
|
|
|
|
|
#set -x
|
|
|
|
|
|
|
|
parent_dir="${PWD}/../../"
|
|
|
|
unpatched_parent_dir="../../src/unpatched-fonts/"
|
|
|
|
to="$parent_dir/10-nerd-font-symbols.conf"
|
|
|
|
symbolfont="Symbols Nerd Font"
|
2017-05-14 00:02:53 +02:00
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
2018-03-01 04:36:52 +02:00
|
|
|
families=()
|
2016-11-30 05:48:54 +02:00
|
|
|
|
|
|
|
cd $unpatched_parent_dir || {
|
2017-05-14 00:02:53 +02:00
|
|
|
echo >&2 "$LINE_PREFIX Could not find patched fonts directory"
|
2016-11-30 05:48:54 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# clear output file (needed for multiple runs or updates):
|
2018-01-13 05:20:52 +02:00
|
|
|
true > "$to" 2> /dev/null
|
2016-11-30 05:48:54 +02:00
|
|
|
|
|
|
|
# add to the file
|
|
|
|
{
|
|
|
|
printf '<?xml version="1.0"?>'
|
|
|
|
printf '\n<!DOCTYPE fontconfig SYSTEM "fonts.dtd">'
|
|
|
|
printf '\n<fontconfig>'
|
|
|
|
} >> "$to"
|
|
|
|
|
2018-03-01 03:28:41 +02:00
|
|
|
|
|
|
|
echo "$LINE_PREFIX Generating fontconfig for: monospace"
|
|
|
|
|
|
|
|
# ad hoc add 'monospace' font family
|
|
|
|
{
|
|
|
|
printf '\n <alias>'
|
|
|
|
printf '\n <family>monospace</family>'
|
|
|
|
printf '\n <prefer><family>%s</family></prefer>' "$symbolfont"
|
|
|
|
printf '\n </alias>'
|
|
|
|
} >> "$to"
|
|
|
|
|
2016-11-30 05:48:54 +02:00
|
|
|
#find ./Hack -maxdepth 0 -type d | # uncomment to test 1 font
|
|
|
|
find . -maxdepth 1 -type d | # uncomment to get all fonts
|
|
|
|
while read -r filename
|
|
|
|
do
|
|
|
|
|
|
|
|
searchdir=$filename
|
|
|
|
|
|
|
|
FONTS=()
|
|
|
|
while IFS= read -d $'\0' -r file ; do
|
|
|
|
FONTS=("${FONTS[@]}" "$file")
|
|
|
|
# limit to first variation of family (folder)
|
2018-03-01 04:36:52 +02:00
|
|
|
done < <(find "$searchdir" -type f -iname '*.[o,t]tf' -print0)
|
|
|
|
#done
|
|
|
|
|
|
|
|
for font in "${FONTS[@]}"; do
|
|
|
|
familyname=$(fc-query --format='%{family}' "${font}")
|
2018-03-01 04:41:46 +02:00
|
|
|
if [[ ! "${families[*]}" == *"${familyname}"* ]]; then
|
2018-03-01 04:36:52 +02:00
|
|
|
# family array doesn't contain the font yet
|
|
|
|
# so let's add it
|
|
|
|
families+=("$familyname")
|
|
|
|
echo "adding $familyname";
|
|
|
|
|
|
|
|
echo "$LINE_PREFIX Generating fontconfig for: $familyname"
|
|
|
|
|
|
|
|
# add to the file
|
|
|
|
{
|
|
|
|
printf '\n <alias>'
|
|
|
|
printf '\n <family>%s</family>' "$familyname"
|
|
|
|
printf '\n <prefer><family>%s</family></prefer>' "$symbolfont"
|
|
|
|
printf '\n </alias>'
|
|
|
|
} >> "$to"
|
|
|
|
|
|
|
|
else
|
|
|
|
echo "no need to add $familyname";
|
|
|
|
fi
|
|
|
|
done
|
2016-11-30 05:48:54 +02:00
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
# add to the file
|
|
|
|
{
|
2018-01-13 05:20:52 +02:00
|
|
|
printf "\\n</fontconfig>\\n"
|
2016-11-30 05:48:54 +02:00
|
|
|
} >> "$to"
|
|
|
|
|