Peter Lyons

New Work Journal System

January 15, 2019

I've updated my journaling tooling for my work journal. Here's how I do it.

Writing Journal Entries

First, a script computes the path to the specific journal (one per job/company) I'm using.

#!/usr/bin/env bash
# Strict mode boilerplate omitted for the blog, but is really there
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
year=$(date +%Y)
month=$(date +%m)
day=$(date +%d)
journal_path="${HOME}/work/journal/${year}-${month}/${year}-${month}-${day}.md"
exec ~/bin/append-journal-entry.sh "${journal_path}"

There's a script append-journal-entry.sh that looks like this:

#!/usr/bin/env bash
# Strict mode boilerplate omitted for the blog, but is really there
# http://redsymbol.net/articles/unofficial-bash-strict-mode/

cd "$(dirname "${BASH_SOURCE[0]}")/.."

main() {
  local journal_path=$1
  shift
  local entry
  entry="$*"
  if [[ -z "${entry}" ]]; then
    entry=$(~/bin/prompt-or-clipboard.sh "Entry")
  fi
  mkdir -p "$(dirname "${journal_path}")"
  local ts
  ts=$(date +%Y-%m-%dT%H:%M:%S%z)
  cat <<EOF >>"${journal_path}"

# ${ts}
- ${entry}
EOF
}

main "$@"

Here's prompt-or-clipboard.sh

read -r -p "$1 (ENTER for clipboard): " query
if [[ -z "${query}" ]]; then
  query=$(xclip -clipboard -o)
fi
echo "${query}"

Searching the Journal

I use this shell alias

search-work-journal() {
  rg "$*" ~/work/journal | less
}

Reading the full journal

read-work-journal() {
  fd --type f . ~/work/journal | xargs cat | less
}