2023-09-27 10:48:32 +02:00
|
|
|
#!/usr/bin/env bash
|
2024-04-12 16:31:51 +02:00
|
|
|
# Nerd Fonts Version: 3.2.1
|
2023-09-27 10:48:32 +02:00
|
|
|
# Script Version: 1.0.0
|
|
|
|
#
|
|
|
|
# Edits the repo's .gitignore to prevent patched font artifacts
|
|
|
|
# to be included, if that font is set to be not repo-released.
|
|
|
|
# to be included, if that font is set to be not repo-released.
|
|
|
|
#
|
|
|
|
# Example run
|
|
|
|
# update-gitignore.sh
|
|
|
|
|
|
|
|
# set -x
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Get script directory to set source and target dirs relative to it
|
|
|
|
sd="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit ; pwd -P )"
|
|
|
|
repo_root_dir=$(dirname "$(dirname "${sd}")") # two levels up (i.e. ../../)
|
|
|
|
|
|
|
|
gitignore=${repo_root_dir}/.gitignore
|
|
|
|
gitignore_tmp=${gitignore}~
|
|
|
|
|
|
|
|
delimiter="# AUTOGENERATED"
|
|
|
|
|
|
|
|
num_comments=$(grep -c "^${delimiter}" "${gitignore}")
|
|
|
|
if [ "${num_comments}" -ne 2 ]; then
|
|
|
|
echo "Fatal: Unexpected number of delimiting lines in gitignore file"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -f "${gitignore_tmp}" ]; then
|
|
|
|
echo "Fatal: Temporary file ${gitignore_tmp} already exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
while IFS=$'\n' read -r line; do
|
|
|
|
if [[ "${line}" =~ ^"${delimiter}" ]]; then
|
|
|
|
if [ -z "${remove}" ]; then
|
|
|
|
remove=1
|
|
|
|
else
|
|
|
|
unset remove
|
|
|
|
fi
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [ -z "${remove}" ]; then
|
|
|
|
printf '%s\n' "$line" >> "${gitignore_tmp}"
|
|
|
|
fi
|
|
|
|
done < "$gitignore"
|
|
|
|
|
|
|
|
i=0
|
|
|
|
{
|
|
|
|
echo "${delimiter} lines follow, do not change or remove the comments"
|
|
|
|
echo "# Non-Repo-Released fonts, see fonts.json:"
|
|
|
|
while IFS=$'\n' read -r dir; do
|
|
|
|
echo "patched-fonts/${dir// /\\ }/*"
|
|
|
|
echo "!patched-fonts/${dir// /\\ }/README.md"
|
|
|
|
i=$((i + 1))
|
|
|
|
done < <(jq -r '.fonts[] | select(.repoRelease == false) | .folderName' lib/fonts.json)
|
|
|
|
echo "${delimiter} lines end"
|
|
|
|
} >> "${gitignore_tmp}"
|
|
|
|
|
|
|
|
echo "Created entries for ${i} fonts in ${gitignore_tmp}"
|
|
|
|
mv -v -- "${gitignore_tmp}" "${gitignore}"
|