Skip to content

Instantly share code, notes, and snippets.

@sloev
Created March 16, 2023 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sloev/42f848e93a20af67f147a8f031ef282d to your computer and use it in GitHub Desktop.
Save sloev/42f848e93a20af67f147a8f031ef282d to your computer and use it in GitHub Desktop.
use gitjournal
  1. create repo

  2. install https://gitjournal.io/ on phone

  3. setup gitjournal on phone

  4. clone repo on computer

  5. install script alias

$ echo "alias journal=\"python `pwd`/journal.py\"" > ~/.zshrc
import readline
import datetime
import os
journal_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "journal")
now = datetime.datetime.now().isoformat().rsplit(".", 1)[0]
readline.set_startup_hook(lambda: readline.insert_text(now))
try:
date = input("📅 entry date: ") # or raw_input in Python 2
finally:
readline.set_startup_hook()
lines = []
while True:
prompt = ""
if not lines:
prompt = "write journal entry, end with double enter:\n"
line = input(prompt)
if len(lines)>0 and line == "":
break
lines.append(line)
template = """---
created: {date}:00:00+01:00
modified: {date}:00:00+01:00
---
{contents}
"""
with open(os.path.join(journal_dir, f"{date}.md"), "w") as fout:
fout.write(template.format(date=date, contents="\n\n".join(lines)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment