first push, simple Typst Helper
This commit is contained in:
commit
bbb66dc0a2
1 changed files with 41 additions and 0 deletions
41
typ
Executable file
41
typ
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/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()
|
Loading…
Add table
Add a link
Reference in a new issue