Files
mytoolkit/mycli/commands/bib.py
T

55 lines
1.5 KiB
Python

"""BibTeX utilities."""
import subprocess
from pathlib import Path
import click
from mycli.config import config
from mycli.utils import handle_errors, run_command
@click.group()
def bib():
"""BibTeX and bibliography commands."""
pass
@bib.command("to-markdown")
@click.argument("files", nargs=-1, required=True)
@click.option("--dry-run", "-n", is_flag=True, help="Show what would be done")
@handle_errors
def to_markdown(files, dry_run):
"""Convert BibTeX files to Markdown."""
for pattern in files:
for bib_file in Path(".").glob(pattern):
if bib_file.suffix.lower() != ".bib":
continue
output = bib_file.with_suffix(".md")
if dry_run:
click.echo(f"Would convert: {bib_file} -> {output}")
continue
click.echo(f"Converting: {bib_file} -> {output}")
content = bib_file.read_text()
md_content = f"# Bibliography\n\n```bibtex\n{content}\n```\n"
output.write_text(md_content)
@bib.command("cv-update")
@handle_errors
def cv_update():
"""Update CV bibliography using biber."""
cv_path = config.get_path("cv")
if not cv_path:
# Fallback to hardcoded path
cv_path = Path.home() / "Documents/Personal/resume_cv/cv_lai_maintaining_latex/cv_lai_maintaining"
if not cv_path.exists():
click.echo(f"CV file not found: {cv_path}")
return
click.echo(f"Updating CV bibliography: {cv_path}")
run_command(["biber", str(cv_path)], check=False)