Last active
February 2, 2021 06:55
-
-
Save afcapel/5a1ff812e9b637519a83147b0a745851 to your computer and use it in GitHub Desktop.
Script at ~/bin/journal I use to keep a journaling practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 named2021-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).