2018-07-09 16:20:40 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-04-27 21:12:32 +02:00
|
|
|
# Nerd Fonts Version: 3.0.0
|
2019-08-17 21:21:36 +02:00
|
|
|
# Script Version: 1.1.0
|
2016-10-29 22:45:55 +02:00
|
|
|
# Iterates over all patched fonts directories
|
|
|
|
# converts all non markdown readmes to markdown (e.g., txt, rst) using pandoc
|
|
|
|
# adds information on additional-variations and complete font variations
|
|
|
|
|
2023-04-25 17:56:56 +02:00
|
|
|
infofilename="README.md"
|
2016-10-29 22:45:55 +02:00
|
|
|
unpatched_parent_dir="src/unpatched-fonts"
|
|
|
|
patched_parent_dir="patched-fonts"
|
2017-05-14 00:02:53 +02:00
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
2023-04-25 11:51:26 +02:00
|
|
|
fonts_info="../../bin/scripts/lib/fonts.json"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
cd ../../src/unpatched-fonts/ || {
|
2017-05-14 00:02:53 +02:00
|
|
|
echo >&2 "$LINE_PREFIX Could not find source fonts directory"
|
2016-10-29 22:45:55 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
|
|
|
|
function appendRfnInfo {
|
|
|
|
local config_rfn=$1; shift
|
|
|
|
local config_rfn_substitue=$1; shift
|
|
|
|
local working_dir=$1; shift
|
|
|
|
local to=$1; shift
|
|
|
|
if [ "$config_rfn" ] && [ "$config_rfn_substitue" ]
|
|
|
|
then
|
|
|
|
# add to the file
|
|
|
|
{
|
2018-01-13 05:20:52 +02:00
|
|
|
printf "\\n## Why \`%s\` and not \`%s\`?\\n" "$config_rfn_substitue" "$config_rfn"
|
2017-07-29 19:43:23 +02:00
|
|
|
cat "$working_dir/../../src/readme-rfn-addendum.md"
|
|
|
|
} >> "$to"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearDestination {
|
|
|
|
local to_dir=$1; shift
|
|
|
|
local to=$1; shift
|
|
|
|
[[ -d "$to_dir" ]] || mkdir -p "$to_dir"
|
|
|
|
# clear output file (needed for multiple runs or updates):
|
2018-01-13 05:20:52 +02:00
|
|
|
true > "$to" 2> /dev/null
|
2017-07-29 19:43:23 +02:00
|
|
|
}
|
|
|
|
|
2023-04-28 12:00:45 +02:00
|
|
|
if [ $# -ge 1 ]; then
|
2019-08-17 21:21:36 +02:00
|
|
|
like_pattern="./$1"
|
|
|
|
# allows one to limit to specific font.
|
|
|
|
# e.g. with ProFont, DejaVuSansMon, Hasklig, Hack, Gohu, FiraCode, Hermit, etc.
|
|
|
|
echo "$LINE_PREFIX Parameter given, limiting find command of directories to pattern '$like_pattern' given"
|
|
|
|
else
|
|
|
|
like_pattern="."
|
|
|
|
echo "$LINE_PREFIX No parameter pattern given, generating standardized readmes for all fonts in all font directories"
|
|
|
|
fi
|
2023-04-28 12:00:45 +02:00
|
|
|
if [ $# -ge 2 ]; then
|
|
|
|
patched_parent_dir=$2
|
|
|
|
echo "$LINE_PREFIX Using destination '${patched_parent_dir}'"
|
|
|
|
fi
|
2019-08-17 21:21:36 +02:00
|
|
|
|
|
|
|
find "$like_pattern" -type d |
|
2016-10-29 22:45:55 +02:00
|
|
|
while read -r filename
|
|
|
|
do
|
|
|
|
|
2017-07-29 18:04:55 +02:00
|
|
|
if [[ "$filename" == "." ]];
|
|
|
|
then
|
|
|
|
echo "$LINE_PREFIX Skipping directory '.'"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2017-07-23 17:28:10 +02:00
|
|
|
base_directory=$(echo "$filename" | cut -d "/" -f2)
|
2023-04-27 20:58:54 +02:00
|
|
|
searchdir=$base_directory
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
# limit looking for the readme files in the parent dir not the child dirs:
|
2023-04-27 20:58:54 +02:00
|
|
|
if [ "$dirname" != "." -a -n "$dirname" ];
|
2023-04-27 08:04:24 +02:00
|
|
|
then
|
|
|
|
searchdir=$dirname
|
2017-07-23 17:28:10 +02:00
|
|
|
else
|
2023-04-25 10:31:43 +02:00
|
|
|
# reset the variables
|
|
|
|
unset config_rfn
|
|
|
|
unset config_rfn_substitue
|
2023-04-25 11:51:26 +02:00
|
|
|
fontdata=$(cat ${fonts_info} | jq ".fonts[] | select(.folderName == \"${base_directory}\")")
|
|
|
|
if [ "$(echo $fontdata | jq .RFN)" = "true" ]
|
2017-07-23 17:28:10 +02:00
|
|
|
then
|
2023-04-25 11:51:26 +02:00
|
|
|
config_rfn=$(echo $fontdata | jq -r .unpatchedName)
|
|
|
|
config_rfn_substitue=$(echo $fontdata | jq -r .patchedName)
|
|
|
|
if [ "${config_rfn}" = "${config_rfn_substitue}" ]
|
|
|
|
then
|
|
|
|
# Only the case with Mononoki which is RFN but we do not rename (we got the permission to keep the name)
|
|
|
|
unset config_rfn
|
|
|
|
unset config_rfn_substitue
|
|
|
|
fi
|
2017-07-23 17:28:10 +02:00
|
|
|
fi
|
2023-04-27 08:04:24 +02:00
|
|
|
fi
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
mapfile -t RST < <(find "$searchdir" -type f -iname 'readme.rst')
|
|
|
|
mapfile -t TXT < <(find "$searchdir" -type f -iname 'readme.txt')
|
|
|
|
mapfile -t MD < <(find "$searchdir" -type f -iname 'readme.md')
|
2023-04-28 12:00:45 +02:00
|
|
|
outputdir=$PWD/../../${patched_parent_dir}/$filename/
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
echo "$LINE_PREFIX Generating readme for: $filename"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
[[ -d "$outputdir" ]] || mkdir -p "$outputdir"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
if [ "${RST[0]}" ];
|
|
|
|
then
|
|
|
|
for i in "${RST[@]}"
|
|
|
|
do
|
|
|
|
echo "$LINE_PREFIX Found RST"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
from="$PWD/$i"
|
|
|
|
to_dir="${PWD/$unpatched_parent_dir/$patched_parent_dir}/$filename"
|
|
|
|
to="${to_dir}/$infofilename"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
clearDestination "$to_dir" "$to"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
pandoc "$from" --from=rst --to=markdown --output="$to"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
appendRfnInfo "$config_rfn" "$config_rfn_substitue" "$PWD" "$to"
|
|
|
|
cat "$PWD/../../src/readme-per-directory-addendum.md" >> "$to"
|
2023-04-27 08:04:24 +02:00
|
|
|
done
|
|
|
|
elif [ "${TXT[0]}" ];
|
|
|
|
then
|
|
|
|
for i in "${TXT[@]}"
|
|
|
|
do
|
|
|
|
echo "$LINE_PREFIX Found TXT"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
from="$PWD/$i"
|
|
|
|
to_dir="${PWD/$unpatched_parent_dir/$patched_parent_dir}/$filename"
|
|
|
|
to="${to_dir}/$infofilename"
|
2016-11-01 04:00:05 +02:00
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
clearDestination "$to_dir" "$to"
|
2016-11-01 04:00:05 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
cp "$from" "$to"
|
2016-11-01 04:00:05 +02:00
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
appendRfnInfo "$config_rfn" "$config_rfn_substitue" "$PWD" "$to"
|
|
|
|
cat "$PWD/../../src/readme-per-directory-addendum.md" >> "$to"
|
2023-04-27 08:04:24 +02:00
|
|
|
done
|
|
|
|
elif [ "${MD[0]}" ];
|
|
|
|
then
|
|
|
|
for i in "${MD[@]}"
|
|
|
|
do
|
|
|
|
echo "$LINE_PREFIX Found MD"
|
2016-11-01 04:00:05 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
from="$PWD/$i"
|
|
|
|
to_dir="${PWD/$unpatched_parent_dir/$patched_parent_dir}/$filename"
|
|
|
|
to="${to_dir}/$infofilename"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
clearDestination "$to_dir" "$to"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2023-04-27 08:04:24 +02:00
|
|
|
cp "$from" "$to"
|
2016-10-29 22:45:55 +02:00
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
appendRfnInfo "$config_rfn" "$config_rfn_substitue" "$PWD" "$to"
|
|
|
|
cat "$PWD/../../src/readme-per-directory-addendum.md" >> "$to"
|
2023-04-27 08:04:24 +02:00
|
|
|
done
|
|
|
|
else
|
2017-07-23 17:28:10 +02:00
|
|
|
echo "$LINE_PREFIX Did not find any readme files (RST,TXT,MD) generating just title of Font"
|
|
|
|
|
|
|
|
to_dir="${PWD/$unpatched_parent_dir/$patched_parent_dir}/$filename"
|
|
|
|
to="${to_dir}/$infofilename"
|
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
clearDestination "$to_dir" "$to"
|
2017-07-23 17:28:10 +02:00
|
|
|
|
|
|
|
{
|
2018-01-13 05:20:52 +02:00
|
|
|
printf "# %s\\n\\n" "$base_directory"
|
2017-07-23 17:28:10 +02:00
|
|
|
} >> "$to"
|
|
|
|
|
2017-07-29 19:43:23 +02:00
|
|
|
appendRfnInfo "$config_rfn" "$config_rfn_substitue" "$PWD" "$to"
|
2017-07-23 17:28:10 +02:00
|
|
|
cat "$PWD/../../src/readme-per-directory-addendum.md" >> "$to"
|
2023-04-27 08:04:24 +02:00
|
|
|
fi
|
2016-10-29 22:45:55 +02:00
|
|
|
|
|
|
|
done
|