Initial version of the E-Invoice solution of JR IT Services
This commit is contained in:
20
jr_einvoice/editor.py
Normal file
20
jr_einvoice/editor.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from __future__ import annotations
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
def open_in_editor(path: Path, logger) -> None:
|
||||
# Prefer $EDITOR, then common editors
|
||||
editor = os.environ.get("EDITOR")
|
||||
if not editor:
|
||||
for cand in ["code", "codium", "nano", "vim", "vi"]:
|
||||
if shutil.which(cand):
|
||||
editor = cand
|
||||
break
|
||||
if not editor:
|
||||
raise RuntimeError("No editor found. Set $EDITOR or install nano/vim/code.")
|
||||
logger.info("Opening editor: %s %s", editor, path)
|
||||
# Split editor if it contains args (simple)
|
||||
parts = editor.split()
|
||||
subprocess.run(parts + [str(path)], check=False)
|
||||
Reference in New Issue
Block a user