Skip to content

Commit

Permalink
gotta-patch-em: Correct file type of config files
Browse files Browse the repository at this point in the history
[why]
The config files are called `config.json` while the contents is
INI-like. The usual extension would be `.cfg`.

[how]
We use `.cfg` already for the shell variable configuration.

Combine both config file variants into one (real) cfg file, that is
directly read by the font-patcher and no shell variables files are used
anymore.

This needs some rewrite in gotta-patch-em to get the quoting right.
To make this simpler we remove the `--debug 1` option from the variable
and insert it directly (as it is applied always anyhow).

Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Apr 22, 2024
1 parent b984447 commit 88d63ff
Show file tree
Hide file tree
Showing 55 changed files with 134 additions and 129 deletions.
46 changes: 16 additions & 30 deletions bin/scripts/gotta-patch-em-all-font-patcher!.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,32 +214,19 @@ function patch_font {
config_parent_dir=$( cd "$( dirname "$f" )" && cd ".." && pwd)
config_dir=$( cd "$( dirname "$f" )" && pwd)

# source the font config file if exists:
# fetches for example config_patch_flags
unset config_patch_flags
# find the font config file:
if [ -f "$config_dir/config.cfg" ]
then
# shellcheck source=/dev/null
source "$config_dir/config.cfg"
font_config="--configfile=$config_dir/config.cfg"
elif [ -f "$config_parent_dir/config.cfg" ]
then
# shellcheck source=/dev/null
source "$config_parent_dir/config.cfg"
font_config="--configfile=$config_parent_dir/config.cfg"
elif [ -f "$(find_font_root "$config_parent_dir")/config.cfg" ]
then
# shellcheck source=/dev/null
source "$(find_font_root "$config_parent_dir")/config.cfg"
fi

if [ -f "$config_dir/config.json" ]
then
# load font configuration file and remove selected ligatures:
font_config="--removeligatures --configfile $config_dir/config.json"
elif [ -f "$config_parent_dir/config.json" ]
then
font_config="--removeligatures --configfile $config_parent_dir/config.json"
font_config="--configfile=$(find_font_root "$config_parent_dir")/config.cfg"
else
font_config=""
# We need to give some argument because empty arguments will break the patcher call
font_config="-q"
fi

if [ "$post_process" ]
Expand All @@ -255,38 +242,37 @@ function patch_font {
echo >&2 "# Could not find project parent directory"
exit 3
}
# Add logfile always (but can be overridden by config_patch_flags in config.cfg and env var NERDFONTS)
config_patch_flags="--debug 1 ${config_patch_flags}"
# Add logfile always (but can be overridden by config.cfg and env var NERDFONTS)
# Use absolute path to allow fontforge being an AppImage (used in CI)
PWD=$(pwd)
# Create "Nerd Font"
if [ -n "${verbose}" ]
then
echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}"
echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}"
fi
# shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q ${font_config} $post_process -c --no-progressbars \
--outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q "${font_config}" $post_process -c --no-progressbars \
--outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
# shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block
if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi
# Create "Nerd Font Mono"
if [ -n "${verbose}" ]
then
echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q -s ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}"
echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q -s \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}"
fi
# shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q -s ${font_config} $post_process -c --no-progressbars \
--outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q -s "${font_config}" $post_process -c --no-progressbars \
--outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
# shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block
if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi
# Create "Nerd Font Propo"
if [ -n "${verbose}" ]
then
echo "fontforge -quiet -script \"${PWD}/font-patcher\" \"$f\" -q --variable ${font_config} $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" $config_patch_flags ${NERDFONTS}"
echo "fontforge -quiet -script \"${PWD}/font-patcher\" --debug 1 \"$f\" -q --variable \"${font_config}\" $post_process -c --no-progressbars --outputdir \"${patched_font_dir}\" ${NERDFONTS}"
fi
# shellcheck disable=SC2086 # We want splitting for the unquoted variables to get multiple options out of them
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" "$f" -q --variable ${font_config} $post_process -c --no-progressbars \
--outputdir "${patched_font_dir}" $config_patch_flags ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
{ OUT=$(fontforge -quiet -script "${PWD}/font-patcher" --debug 1 "$f" -q --variable "${font_config}" $post_process -c --no-progressbars \
--outputdir "${patched_font_dir}" ${NERDFONTS} 2>&1 1>&3 3>&- ); } 3>&1
# shellcheck disable=SC2181 # Checking the code directly is very unreadable here, as we execute a whole block
if [ $? -ne 0 ]; then printf "%s\nPatcher run aborted!\n\n" "$OUT"; fi

Expand Down
4 changes: 2 additions & 2 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ def setup_arguments():

expert_group = parser.add_argument_group('Expert Options')
expert_group.add_argument('--boxdrawing', dest='forcebox', default=False, action='store_true', help='Force patching in (over existing) box drawing glyphs')
expert_group.add_argument('--configfile', dest='configfile', default=False, type=str, help='Specify a file path for JSON configuration file (see sample: src/config.sample.json)')
expert_group.add_argument('--configfile', dest='configfile', default=False, type=str, help='Specify a file path for configuration file (see sample: src/config.sample.cfg)')
expert_group.add_argument('--custom', dest='custom', default=False, type=str, help='Specify a custom symbol font, all glyphs will be copied; absolute path suggested')

expert_group.add_argument('--dry', dest='dry_run', default=False, action='store_true', help='Do neither patch nor store the font, to check naming')
Expand All @@ -1946,7 +1946,7 @@ def setup_arguments():
expert_group.add_argument('--name', dest='force_name', default=None, type=str, help='Specify naming source (\'full\', \'postscript\', \'filename\', or concrete free name-string)')
expert_group.add_argument('--postprocess', dest='postprocess', default=False, type=str, help='Specify a Script for Post Processing')
progressbars_group_parser = expert_group.add_mutually_exclusive_group(required=False)
expert_group.add_argument('--removeligs', '--removeligatures', dest='removeligatures', default=False, action='store_true', help='Removes ligatures specificed in JSON configuration file (needs --configfile)')
expert_group.add_argument('--removeligs', '--removeligatures', dest='removeligatures', default=False, action='store_true', help='Removes ligatures specificed in configuration file (needs --configfile)')
expert_group.add_argument('--xavgcharwidth', dest='xavgwidth', default=None, type=int, nargs='?', help='Adjust xAvgCharWidth (optional: concrete value)', const=True)
# --xavgcharwidth for compatibility with old applications like notepad and non-latin fonts
# Possible values with examples:
Expand Down
9 changes: 9 additions & 0 deletions src/config.sample.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# These config files are read by the font-patcher
# They are INI style files, but some keys have JSON values
[Config]
commandline: --removeligatures --makegroups 2
[Subtables]
ligatures: [
"'dlig' Discretionary Ligatures lookup 9 subtable",
"'dlig' Discretionary Ligatures lookup 11 subtable",
"'dlig' Discretionary Ligatures lookup 12 contextual 0" ]
18 changes: 0 additions & 18 deletions src/config.sample.json

This file was deleted.

3 changes: 2 additions & 1 deletion src/unpatched-fonts/3270/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 2"
[Config]
commandline: --makegroups 2
3 changes: 2 additions & 1 deletion src/unpatched-fonts/BitstreamVeraSansMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--has-no-italic"
[Config]
commandline: --has-no-italic
3 changes: 2 additions & 1 deletion src/unpatched-fonts/CascadiaCode/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
3 changes: 2 additions & 1 deletion src/unpatched-fonts/CascadiaMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
3 changes: 2 additions & 1 deletion src/unpatched-fonts/D2Coding/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--xavgcharwidth 500"
[Config]
commandline: --xavgcharwidth 500
3 changes: 2 additions & 1 deletion src/unpatched-fonts/DaddyTimeMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--ext ttf"
[Config]
commandline: --ext ttf
3 changes: 2 additions & 1 deletion src/unpatched-fonts/DejaVuSansMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--has-no-italic"
[Config]
commandline: --has-no-italic
1 change: 0 additions & 1 deletion src/unpatched-fonts/DroidSansMono/config.cfg

This file was deleted.

1 change: 0 additions & 1 deletion src/unpatched-fonts/FantasqueSansMono/config.cfg

This file was deleted.

4 changes: 2 additions & 2 deletions src/unpatched-fonts/FiraCode/config.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
config_has_powerline=1
config_patch_flags="--makegroups 2"
[Config]
commandline: --makegroups 2
3 changes: 2 additions & 1 deletion src/unpatched-fonts/GeistMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
1 change: 0 additions & 1 deletion src/unpatched-fonts/Hack/config.cfg

This file was deleted.

4 changes: 2 additions & 2 deletions src/unpatched-fonts/Hasklig/config.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
config_has_powerline=1
config_patch_flags="--makegroups 2"
[Config]
commandline: --makegroups 2
1 change: 0 additions & 1 deletion src/unpatched-fonts/Hermit/config.cfg

This file was deleted.

1 change: 0 additions & 1 deletion src/unpatched-fonts/IBMPlexMono/config.cfg

This file was deleted.

3 changes: 2 additions & 1 deletion src/unpatched-fonts/IntelOneMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
4 changes: 2 additions & 2 deletions src/unpatched-fonts/Iosevka/config.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
config_has_powerline=1
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
4 changes: 2 additions & 2 deletions src/unpatched-fonts/IosevkaTerm/config.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
config_has_powerline=1
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
4 changes: 2 additions & 2 deletions src/unpatched-fonts/IosevkaTermSlab/config.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
config_has_powerline=1
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
3 changes: 2 additions & 1 deletion src/unpatched-fonts/JetBrainsMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
6 changes: 6 additions & 0 deletions src/unpatched-fonts/Lekton/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Config]
commandline: --removeligatures
[Subtables]
ligatures: [
"'liga' Standard Ligatures in Latin lookup 6 subtable",
"'liga' Standard Ligatures in Latin lookup 5 subtable" ]
4 changes: 0 additions & 4 deletions src/unpatched-fonts/Lekton/config.json

This file was deleted.

3 changes: 2 additions & 1 deletion src/unpatched-fonts/MPlus/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 2"
[Config]
commandline: --makegroups 2
3 changes: 2 additions & 1 deletion src/unpatched-fonts/MartianMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--name filename --makegroups 5"
[Config]
commandline: --name filename --makegroups 5
1 change: 0 additions & 1 deletion src/unpatched-fonts/Meslo/config.cfg

This file was deleted.

3 changes: 2 additions & 1 deletion src/unpatched-fonts/Monaspace/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
1 change: 0 additions & 1 deletion src/unpatched-fonts/Monofur/config.cfg

This file was deleted.

3 changes: 2 additions & 1 deletion src/unpatched-fonts/NerdFontsSymbolsOnly/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--ext ttf --variable-width-glyphs"
[Config]
commandline: --ext ttf --variable-width-glyphs
7 changes: 7 additions & 0 deletions src/unpatched-fonts/Noto/Sans-Mono/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Config]
commandline: --removeligatures --makegroups 5
[Subtables]
ligatures: [
"Ligature Substitution lookup 15 subtable",
"Ligature Substitution lookup 14 subtable",
"Ligature Substitution lookup 13 subtable" ]
5 changes: 0 additions & 5 deletions src/unpatched-fonts/Noto/Sans-Mono/config.json

This file was deleted.

8 changes: 8 additions & 0 deletions src/unpatched-fonts/Noto/Sans/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Config]
commandline: --removeligatures --makegroups 5
[Subtables]
ligatures: [
"'liga' Standard Ligatures lookup 41 subtable",
"Ligature Substitution lookup 15 subtable",
"Ligature Substitution lookup 14 subtable",
"Ligature Substitution lookup 13 subtable" ]
6 changes: 0 additions & 6 deletions src/unpatched-fonts/Noto/Sans/config.json

This file was deleted.

3 changes: 2 additions & 1 deletion src/unpatched-fonts/Noto/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 5"
[Config]
commandline: --makegroups 5
8 changes: 8 additions & 0 deletions src/unpatched-fonts/OpenDyslexic/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Config]
commandline: --removeligatures
[Subtables]
ligatures: [
"Ligature Substitution lookup 8 subtable",
"Ligature Substitution lookup 7 subtable",
"'liga' Standard Ligature lookup 7 subtable",
"'liga' Standard Ligature lookup 4 subtable" ]
6 changes: 0 additions & 6 deletions src/unpatched-fonts/OpenDyslexic/config.json

This file was deleted.

5 changes: 5 additions & 0 deletions src/unpatched-fonts/Overpass/Mono/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Config]
commandline: --removeligatures --makegroups 2
[Subtables]
ligatures: [
"Ligature Substitution lookup 23 subtable" ]
3 changes: 0 additions & 3 deletions src/unpatched-fonts/Overpass/Mono/config.json

This file was deleted.

6 changes: 6 additions & 0 deletions src/unpatched-fonts/Overpass/Non-Mono/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Config]
commandline: --removeligatures --makegroups 2
[Subtables]
ligatures: [
"Ligature Substitution lookup 20 subtable",
"'liga' Standard Ligatures in Latin lookup 18 subtable" ]
4 changes: 0 additions & 4 deletions src/unpatched-fonts/Overpass/Non-Mono/config.json

This file was deleted.

1 change: 0 additions & 1 deletion src/unpatched-fonts/Overpass/config.cfg

This file was deleted.

3 changes: 2 additions & 1 deletion src/unpatched-fonts/RobotoMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 3"
[Config]
commandline: --makegroups 3
4 changes: 2 additions & 2 deletions src/unpatched-fonts/SourceCodePro/config.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
config_has_powerline=1
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
6 changes: 6 additions & 0 deletions src/unpatched-fonts/SpaceMono/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Config]
commandline: --removeligatures
[Subtables]
ligatures: [
"'liga' Standard Ligatures in Latin lookup 9 subtable",
"'liga' Standard Ligatures in Latin lookup 8 subtable" ]
4 changes: 0 additions & 4 deletions src/unpatched-fonts/SpaceMono/config.json

This file was deleted.

8 changes: 7 additions & 1 deletion src/unpatched-fonts/Ubuntu/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
config_patch_flags="--makegroups 2"
[Config]
commandline: --removeligatures --makegroups 2
[Subtables]
ligatures: [
"'liga' Standard Ligatures in Latin lookup 20 subtable",
"'liga' Standard Ligatures in Greek lookup 21 subtable",
"'liga' Standard Ligatures in Cyrillic lookup 22 subtable" ]
5 changes: 0 additions & 5 deletions src/unpatched-fonts/Ubuntu/config.json

This file was deleted.

3 changes: 2 additions & 1 deletion src/unpatched-fonts/UbuntuMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 2"
[Config]
commandline: --makegroups 2
3 changes: 2 additions & 1 deletion src/unpatched-fonts/UbuntuSans/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
3 changes: 2 additions & 1 deletion src/unpatched-fonts/VictorMono/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4
3 changes: 2 additions & 1 deletion src/unpatched-fonts/ZedMono/Extended/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 5"
[Config]
commandline: --makegroups 5
3 changes: 2 additions & 1 deletion src/unpatched-fonts/ZedMono/Normal/config.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config_patch_flags="--makegroups 4"
[Config]
commandline: --makegroups 4

0 comments on commit 88d63ff

Please sign in to comment.