initial commit

This commit is contained in:
Jev Kuznetsov
2026-04-16 11:36:48 +02:00
commit 60710fab20
30 changed files with 1460 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
"""Shared helpers for CLI commands."""
import re
import subprocess
from pathlib import Path
YELLOW = "\033[33m"
RESET = "\033[0m"
BASHRC = Path("~/.bashrc").expanduser()
SNIPPETS_DIR = Path(__file__).parent.parent.parent / "snippets"
def load_snippet(name: str) -> str:
"""Read a shell snippet from the snippets directory."""
return (SNIPPETS_DIR / f"{name}.sh").read_text()
def run(cmd: str, pty: bool = False) -> None:
"""Print command in yellow then execute it."""
print(f"{YELLOW}$ {cmd}{RESET}")
subprocess.run(cmd, shell=True, check=True)
def append_bashrc_section(marker: str, content: str) -> None:
"""Idempotently add a named section to ~/.bashrc."""
begin = f"# BEGIN {marker}"
end = f"# END {marker}"
section = f"\n{begin}\n{content.strip()}\n{end}\n"
text = BASHRC.read_text()
text = re.sub(
rf"\n?{re.escape(begin)}.*?{re.escape(end)}\n?", "", text, flags=re.DOTALL
)
BASHRC.write_text(text + section)