Skip to content

Instantly share code, notes, and snippets.

@PsychedelicShayna
Created December 26, 2023 13:10
Show Gist options
  • Save PsychedelicShayna/2c36094de5861b5282ab97d60ba77558 to your computer and use it in GitHub Desktop.
Save PsychedelicShayna/2c36094de5861b5282ab97d60ba77558 to your computer and use it in GitHub Desktop.
A shitty idea basket script that I cooked up in 5 minutes, a temporary solution until I settle on a real utility.
#!/usr/bin/env python
import subprocess
import datetime
import random
import sys
import os
EUREKA_REPOSITORY: str = os.environ.get("EUREKA_REPO_PATH") or os.path.expanduser("~/eureka")
# This is not good code, and I don't really care. Point is to have somewhere to dump ideas and not forget them.
# For now, this is enough.
if __name__ == "__main__":
if EUREKA_REPOSITORY is None:
print("EUREKA_REPO_PATH is not set, point it to a git repository.")
sys.exit(1)
file_name: str = os.path.join(EUREKA_REPOSITORY, str(random.randint(100_000_000, 999_999_999)))
while os.path.exists(file_name):
file_name = str(random.randint(100_000_000, 999_999_999))
file_name += ".md"
with open(file_name, "w+") as f:
f.writelines([os.path.basename(file_name)])
with open(file_name, "r") as f:
old_contents = f.read()
os.system(f"/usr/bin/env nvim --clean \"{file_name}\"")
with open(file_name, "r") as f:
new_contents = f.read()
lines = [line.strip() for line in new_contents.split("\n")]
if old_contents == new_contents:
print("Didn't save anything, exiting.")
os.remove(file_name)
sys.exit(0)
first = lines[0] if len(lines) else ""
os.rename(file_name, os.path.join(EUREKA_REPOSITORY, first))
subprocess.run(["git", "add", first], cwd=EUREKA_REPOSITORY)
subprocess.run(["git", "commit", "-m", f"Eureka on date {datetime.datetime.now()}"], cwd=EUREKA_REPOSITORY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment