41 lines
964 B
Python
Executable file
41 lines
964 B
Python
Executable file
#!/usr/bin/env python3
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
from datetime import datetime
|
|
|
|
if len(sys.argv) < 2:
|
|
print("Usage: typ <filename_base>")
|
|
sys.exit(1)
|
|
|
|
base = sys.argv[1].strip()
|
|
|
|
date_str = datetime.now().strftime("%Y%m%d")
|
|
|
|
filename = f"{base}_{date_str}.typ"
|
|
|
|
if not os.path.isfile(filename):
|
|
print(f"File '{filename}' does not exist.")
|
|
with open(filename, 'w') as f:
|
|
f.write("")
|
|
|
|
with open(os.devnull, "wb") as devnull:
|
|
subprocess.Popen(['code', filename], stdout=devnull, stderr=devnull)
|
|
|
|
typst_proc = subprocess.Popen(['typst', 'watch', filename])
|
|
|
|
pdf_file = f"{base}_{date_str}.pdf"
|
|
|
|
if not os.path.isfile(pdf_file):
|
|
for _ in range(10):
|
|
if os.path.isfile(pdf_file):
|
|
break
|
|
time.sleep(1)
|
|
|
|
if os.path.isfile(pdf_file):
|
|
with open(os.devnull, "wb") as devnull:
|
|
subprocess.Popen(['evince', pdf_file], stdout=devnull, stderr=devnull)
|
|
else:
|
|
pass
|
|
typst_proc.wait()
|