[Jodavaho.io]

Stuff by Josh Vander Hook

Journalling in plain bash

To lower the effort required to actually create and edit entires, I use plain text, in markdown files, backed by GitHub. There are a few tricks I use to keep it manageable. For example, I use separate files for each calendar day, and I structure some of the text so it can be easily parsed. But it’s all quite simple and can be edited via GitHub web, or from the command line on any device I’m using. view full post

I try to make a habit of journalling. It’s been shown to be very good for you, and I love reading old entries or periodically scraping it for data. The big accelerator for my journalling habit was to lower the effort required to actually create and edit entires.

In short, I use plain text, in markdown files, backed by GitHub. There are a few tricks I use to keep it manageable. For example, I use separate files for each calendar day, and I structure some of the text so it can be easily parsed. But it’s all quite simple and can be edited via GitHub web, or from the command line on any device I’m using. I rarely am on my mobile device, so I don’t journal there.

The Basics

You could make a directory to keep journals in:

mkdir ~/.journal

And let’s save it for later use. Edit ~/.bashrc to include:

export logdir=~/.journal

Now, my workflow is that every time I open my journal, I want to see today’s entry, and only today’s. That’s accomplished by separating journal entries by day. I name each one in the format: YYYY-MM-DD.md, which also makes them lexicographically sorted in chronological order, by default.

To generate filenames, we’ll use date. ( see man date ) For our purposes, we want to generate filenames as such:

date "+%Y-%m-%d"

So an auto-generated journal entry would have the filename given by $logdir/$(date +%Y-%m-%d), so we can create the command (again in ~/.bashrc)

alias journal='vim $logdir/$(date +%Y-%m-%d).md'

I use vim, but you could use any editor here.

That’s it, now you can quickly capture journal entries without any overhead. In practice, I have several logging directories, for various research projects, directories for each member of the AI group, and several different personal journals for things like game notes, personal thoughts, or even this writeup.

Editing by date

Suppose you missed an entry, and wanted to log yesterday’s activities. Nobody has time to remember what the date was yesterday, that’s what computers are for. Luckily, we can pass other days to date to output a formatted string. In fact, date will accept a huge variety of strings that it will attempt to parse to figure out what day you actually want to format via the -d switch. With -d a string is required, but the blank string "" defaults to the current day.

To use -d change the above alias to a function, which allows arguments:

function journal(){
    vim $logdir/$(date +%Y-%m-%d -d "$*").md
}

Note, $* passes in all the remaining args, and "$*" evaluates to "" without any args.

Now, you can still say journal as though it were an alias, to edit today’s entry, or you can type things like:


#All these work:
journal yesterday
journal last tuesday
journal 5/11/2014
journal June 13
journal 2 weeks ago

Sync w/ Git

Now suppose you want to back this by GitHub. First, create a repo (GitHub, GitLab, or Keybase can help with this, or you can roll your own). Inside $logdir, go through the usual git init and git remote add ... steps.

Git requires a lot of keystrokes to actually push to a repo. This is to ensure that each commit is well commented with a nice message, merges well with other users' contributions, and so on. But this is your personal journal, who is reading commit comments and who would possibly be contributing? I skip all that by creating a vim command to push directly to GitHub.

Inside ~/.vimrc you could put:

command Lw w | !git add % && git commit % -m "Checkin %" && git push

This custom command will add the current file to the index, commit it with the absolutely terrible commit message “Checkin <filename>”, and push it. Don’t do this for anything other than single-user log files like this. You’ll have to enter your password to actually push, but git credential helper can make that go away.

Conclusion

The full workflow is:

$>journal

... write some stuff ...

:Lw
$>exit

That’s it for a basic but highly functional journal. It’s just one directory in a known location, sync’d by git, with structured filenames and bash aliases to make it very easy to write to. It’s also very easy to parse for data. I’ve seen several attempts to recreate this type of flow in more complicated systems, and tried several, but this is so easy it just works.

Next, we can actually use the markdown format to our advantage with a few more custom vim commands and a little help from bullet journals and the legendary OKR system.

Comments

I have not configured comments for this site yet as there doesn't seem to be any good, free solutions. Please feel free to email, or reach out on social media if you have any thoughts or questions. I'd love to hear from you!