Skip to content

Instantly share code, notes, and snippets.

@nonrice
Created July 4, 2022 18:07
Show Gist options
  • Save nonrice/503836973af3774ec43ca99416216174 to your computer and use it in GitHub Desktop.
Save nonrice/503836973af3774ec43ca99416216174 to your computer and use it in GitHub Desktop.
# Command line tool to manage journal entries
#
# SETUP:
# 1. Install required tools: Vim, FZF
# 2. Replace the contents of JOURNAL_DIR with where you want the journal to be
# 3. (Optional) make an alias in your shell RC to easily run the script
JOURNAL_DIR = "/Users/eric/Workspace/journal"
# HOW TO USE:
# Simply run the file and supply arguments if needed
# no arguments - Opens new journal entry for the day using Vim
# mark - If unmarked, appends an "x" to the entry filename
# unmark - If marked, removes the "x" from the entry filename
# read - Browses the journal directory via FZF
import os, sys, datetime
today = JOURNAL_DIR + "/" + str(datetime.date.today())
marked = False
if os.path.exists(today + "x"):
marked = True
today += "x"
if len(sys.argv) == 1:
os.system("vim " + today)
elif len(sys.argv) == 2:
if sys.argv[1] == "mark":
if not marked and os.path.exists(today): os.system("mv " + today + " " + today + "x")
else: print("journal: Entry is already marked, or entry does not exist")
elif sys.argv[1] == "unmark":
if marked: os.system("mv " + today + " " + today[:-1])
else: print("journal: Entry is not marked")
elif sys.argv[1] == "read":
target = os.system("find " + JOURNAL_DIR + " -type f | sort | fzf --delimiter / --with-nth -1")
if isinstance(target, str):
os.system("vim -R " + target)
else:
print("journal: Bad arguments")
else:
print("journal: Bad arguments")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment