Introduction
Introduction Statistics Contact Development Disclaimer Help
New Script - 2021-07-23 17:52
==============================
wrote a new script to to make it easier to start new posts. Here it is:
#!/usr/bin/env python3
import os
import re
import subprocess
from datetime import datetime
from pathlib import Path
DEFAULT_EXT = '.md'
EDITOR = os.environ.get('EDITOR', 'vim')
title = input('Title: ')
dashed_title = re.sub(r'\s+','-', title)
if not title.strip():
print('Title is empty, aborting')
exit(0)
path = Path(f"{datetime.now():%y%m%d}-{dashed_title.lower()}")
path = path.with_suffix(path.suffix or DEFAULT_EXT)
if input(f'Edit {path!s}? (Y/n): ').lower().strip() in ('', 'y', 'yes'):
header = f"{title} - {datetime.now():%Y-%m-%d %H:%M}"
path.write_text(f"{header}\n{'='*len(header)}")
subprocess.run([EDITOR, path])
t's nothing fancy, but... maybe it's helpful to you!
You are viewing proxied material from circumlunar.space. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.