Skip to content

Instantly share code, notes, and snippets.

@afcapel
Last active February 2, 2021 06:55
Show Gist options
  • Save afcapel/5a1ff812e9b637519a83147b0a745851 to your computer and use it in GitHub Desktop.
Save afcapel/5a1ff812e9b637519a83147b0a745851 to your computer and use it in GitHub Desktop.
Script at ~/bin/journal I use to keep a journaling practice
#!/usr/bin/env ruby --disable-gems
require "date"
require "fileutils"
JOURNAL_DIR = File.expand_path("~/Google Drive/writing/journal")
now = DateTime.now
date = now.strftime("%F")
entry = "#{JOURNAL_DIR}/#{date}.md"
new_entry = !File.exist?(entry)
open(entry, "a") do |f|
if new_entry
f << "# #{now.strftime("%A %d %B %Y %H:%M")}\n\n"
else
f << "\n\n"
f << "# #{now.strftime("%H:%M")}\n\n"
end
end
`open "#{entry}"`
@afcapel
Copy link
Author

afcapel commented Feb 1, 2021

The script creates text files in JOURNAL_DIR with a consistent format and name scheme. I use plain text files to ensure I will be able to read them without too much hassle in the distant feature. The text files contain a heading with the date and time and are named 2021-02-01.md, 2021-01-31.md, etc, so they are chronologically sorted in the directory. If a day has several entries I just add a heading to the existing entry. I can edit those files with any editor (in my case IA Writer) and they are automatically backed up to Google Drive (Dropbox or iCloud would work too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment