mirror of
https://github.com/daylinmorgan/monolisa-nerdfont-patch.git
synced 2024-12-22 06:50:44 -06:00
fix(#4): refactor to reduce some boilerplate
This commit is contained in:
parent
cdb6bacf37
commit
56a06a32c9
4 changed files with 23 additions and 45 deletions
9
Makefile
9
Makefile
|
@ -1,13 +1,10 @@
|
||||||
-include .env
|
-include .env
|
||||||
ARGS ?= -c
|
ARGS ?= -c
|
||||||
|
|
||||||
NF_SRC := $(shell ./bin/get-font-files src)
|
|
||||||
FONT_FLAGS := $(shell ./bin/get-font-files MonoLisa 'otf,ttf,woff,woff2')
|
|
||||||
|
|
||||||
patch: ./bin/font-patcher ## apply nerd fonts patch |> -gs b_magenta -ms bold
|
patch: ./bin/font-patcher ## apply nerd fonts patch |> -gs b_magenta -ms bold
|
||||||
@./bin/patch-monolisa \
|
@./patch-monolisa \
|
||||||
$(FONT_FLAGS) \
|
$(ARGS) \
|
||||||
$(ARGS)
|
-f MonoLisa/
|
||||||
|
|
||||||
update-fonts: ## move fonts and update fc-cache
|
update-fonts: ## move fonts and update fc-cache
|
||||||
$(call msg,Adding Fonts To System)
|
$(call msg,Adding Fonts To System)
|
||||||
|
|
|
@ -11,7 +11,7 @@ tested w/ MonoLisa v2.003
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
- `python`
|
- `python`
|
||||||
- `make`
|
- `make` (optional)
|
||||||
- `fontforge` OR `docker`
|
- `fontforge` OR `docker`
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ you can easily apply the nerd font patches with `make`.
|
||||||
To patch all font types use the default `patch` rule.
|
To patch all font types use the default `patch` rule.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make
|
make # or ./patch-monolisa -f MonoLisa -c
|
||||||
```
|
```
|
||||||
|
|
||||||
By default the complete (`-c`) flag is passed to the font-patcher script to include all icons/symbols.
|
By default the complete (`-c`) flag is passed to the font-patcher script to include all icons/symbols.
|
||||||
|
@ -62,7 +62,7 @@ You can change this by specifying the `ARGS` at runtime.
|
||||||
ARGS="-c -w" make patch
|
ARGS="-c -w" make patch
|
||||||
```
|
```
|
||||||
|
|
||||||
See `./bin/patch-monolisa --help` and `./bin/font-patcher --help` for available `ARGS`.
|
See `./patch-monolisa --help` and `./bin/font-patcher --help` for available `ARGS`.
|
||||||
|
|
||||||
You can find your patched fonts in the `patched/` directory
|
You can find your patched fonts in the `patched/` directory
|
||||||
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
EXTS = ["otf", "ttf", "woff", "woff2"]
|
|
||||||
|
|
||||||
|
|
||||||
def find_files(search_path, exts=None):
|
|
||||||
return (
|
|
||||||
[f for ext in exts for f in search_path.glob(f"**/*.{ext}")]
|
|
||||||
if exts
|
|
||||||
else [f for f in search_path.rglob("*") if f.is_file()]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
print("please specify directory to search")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
search_path = Path(sys.argv[1])
|
|
||||||
exts = sys.argv[2].split(",") if len(sys.argv) == 3 else EXTS
|
|
||||||
|
|
||||||
for f in find_files(search_path, exts):
|
|
||||||
sys.stdout.write(f"-f '{f}' ")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
|
@ -10,7 +10,7 @@ import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Set
|
from typing import List, Set
|
||||||
|
|
||||||
FONT_SRC = (Path(__file__).parent.parent / "MonoLisa").absolute()
|
FONT_SRC = (Path(__file__).parent / "MonoLisa").absolute()
|
||||||
|
|
||||||
|
|
||||||
class Color:
|
class Color:
|
||||||
|
@ -159,7 +159,6 @@ def patch_single_font(
|
||||||
f"{color.yellow}:::{color.end} Patching font "
|
f"{color.yellow}:::{color.end} Patching font "
|
||||||
f"{color.bold}{font_path.name}{color.end}... "
|
f"{color.bold}{font_path.name}{color.end}... "
|
||||||
):
|
):
|
||||||
|
|
||||||
run_cmd(cmd, font_path, verbose)
|
run_cmd(cmd, font_path, verbose)
|
||||||
|
|
||||||
echo(f"{rel_path} patched!", hue="green")
|
echo(f"{rel_path} patched!", hue="green")
|
||||||
|
@ -205,6 +204,17 @@ def patch_font_dir_docker(
|
||||||
echo(f"{font_dir_path.name}/ fonts patched!", hue="green")
|
echo(f"{font_dir_path.name}/ fonts patched!", hue="green")
|
||||||
|
|
||||||
|
|
||||||
|
def get_font_files(p):
|
||||||
|
exts = ["otf", "ttf", "woff", "woff2"]
|
||||||
|
|
||||||
|
if p.is_file():
|
||||||
|
return (p,)
|
||||||
|
|
||||||
|
if p.is_dir():
|
||||||
|
return (f for ext in exts for f in p.glob(f"**/*.{ext}"))
|
||||||
|
return ()
|
||||||
|
|
||||||
|
|
||||||
def echo(msg: str, header=False, hue="cyan") -> None:
|
def echo(msg: str, header=False, hue="cyan") -> None:
|
||||||
if header:
|
if header:
|
||||||
print(f"==>{color.magenta} {msg} {color.end}<==")
|
print(f"==>{color.magenta} {msg} {color.end}<==")
|
||||||
|
@ -213,7 +223,6 @@ def echo(msg: str, header=False, hue="cyan") -> None:
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
echo("MonoLisa NerdFont Patcher", header=True)
|
echo("MonoLisa NerdFont Patcher", header=True)
|
||||||
args, fp_args = get_args()
|
args, fp_args = get_args()
|
||||||
fp_args = " ".join(fp_args)
|
fp_args = " ".join(fp_args)
|
||||||
|
@ -223,12 +232,15 @@ def main():
|
||||||
echo("Patching the following files")
|
echo("Patching the following files")
|
||||||
for fontfile in args.font_path:
|
for fontfile in args.font_path:
|
||||||
sys.stdout.write(f" {color.magenta}->{color.end} {fontfile}\n")
|
sys.stdout.write(f" {color.magenta}->{color.end} {fontfile}\n")
|
||||||
|
|
||||||
|
fontfiles = [f for p in args.font_path for f in get_font_files(p)]
|
||||||
|
|
||||||
if args.docker:
|
if args.docker:
|
||||||
echo("==> DOCKER MODE ENABLED")
|
echo("==> DOCKER MODE ENABLED")
|
||||||
for font_dir in collect_files_by_dir(args.font_path):
|
for font_dir in collect_files_by_dir(fontfiles):
|
||||||
patch_font_dir_docker(font_dir, args.output, fp_args, args.verbose)
|
patch_font_dir_docker(font_dir, args.output, fp_args, args.verbose)
|
||||||
else:
|
else:
|
||||||
for fontfile in args.font_path:
|
for fontfile in fontfiles:
|
||||||
patch_single_font(Path(fontfile), args.output, fp_args, args.verbose)
|
patch_single_font(Path(fontfile), args.output, fp_args, args.verbose)
|
||||||
|
|
||||||
echo("fonts are patched", hue="green")
|
echo("fonts are patched", hue="green")
|
||||||
|
@ -236,6 +248,5 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
color = Color()
|
color = Color()
|
||||||
main()
|
main()
|
Loading…
Reference in a new issue