feat: add script and skill to deduplicate zensical.toml

This commit is contained in:
nιcнolaѕ wιlde
2026-08-05 12:42:15 -07:00
parent c66f017722
commit 46314405df
3 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,18 @@
---
name: dedupe-zensical
description: Remove duplicate array entries in the zensical.toml configuration file.
---
# Dedupe Zensical Skill
This skill removes duplicate array entries in `zensical.toml` (such as duplicate recipe links under menu categories like `Sides = [...]`).
## Usage
When a user requests to deduplicate or remove duplicates from `zensical.toml`, you should simply run the following task:
```bash
task dedupe-zensical
```
This task executes the `scripts/dedupe_zensical.py` Python script, which parses `zensical.toml`, finds exact string duplicates within any array blocks (lines between `[` and `]`), removes them, and overwrites the file in place. It prints the number of duplicates removed.

View File

@ -260,8 +260,12 @@ tasks:
sops --decrypt --input-type json --output-type json --output settings.json settings.json.enc sops --decrypt --input-type json --output-type json --output settings.json settings.json.enc
fi fi
dedupe-zensical:
desc: Remove duplicate array entries in zensical.toml
cmds:
- uv run python3 scripts/dedupe_zensical.py
default: default:
cmds: cmds:
- task -a - task -a
silent: true silent: true

47
scripts/dedupe_zensical.py Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python3
import os
def dedupe_zensical(filepath="zensical.toml"):
if not os.path.exists(filepath):
print(f"Error: {filepath} not found.")
return
with open(filepath, "r") as f:
lines = f.readlines()
new_lines = []
seen_in_section = set()
in_array = False
removed_count = 0
for line in lines:
# Detect the start of an array section (e.g., `Sides = [`)
if "=" in line and "[" in line and "]" not in line:
in_array = True
seen_in_section = set()
new_lines.append(line)
continue
elif "]" in line and in_array:
in_array = False
new_lines.append(line)
continue
if in_array and "{" in line and "}" in line:
trimmed = line.strip()
if trimmed in seen_in_section:
removed_count += 1
continue
seen_in_section.add(trimmed)
new_lines.append(line)
if removed_count > 0:
with open(filepath, "w") as f:
f.writelines(new_lines)
print(f"Successfully removed {removed_count} duplicate entries from {filepath}.")
else:
print(f"No duplicate entries found in {filepath}.")
if __name__ == "__main__":
dedupe_zensical()