Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Last active January 8, 2023 08:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nickanderson/00005b5b03e323a65ada98c5fa5ebb11 to your computer and use it in GitHub Desktop.
Save nickanderson/00005b5b03e323a65ada98c5fa5ebb11 to your computer and use it in GitHub Desktop.

I’m currently using Org-roam to facilitate most new note creation.

Org-roam has a concept of “daily” files. I consider these are collections of nodes that the target location (especially the filename, at least in my case) based on the date.

I use dailies (org-roam-capture-today) for:

  • Recurring meeting notes
    • Daily stand-ups
    • Customer meetings
  • Logging/Journaling
    • Personal journal
    • Work log

I primarily use org-roam-capture for other collections of information. For example, if I were keeping notes about reading a specific book I would likely setup a directory and one or more org-roam-capture-template entries.

mkdir -p ~/org/roam/Books/Learning-CFEngine/

If I didn’t feel like doing a lot of up-front capture template setup then I would probably make one capture template for the book that let me capture to a file per chapter like this:

(setq org-roam-capture-templates
      '(

        ;; This is just a default category which is the org-roam default if you
        ;; don't setup multiple templates.

        ("d" "default"
         plain "%?"
         :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
         :unnarrowed t)

        ;; Books
        ("b" "Books")

        ;; Books Learning CFEngine
        ("bc" "Learning CFEngine" )

        ;; This works, but annoyingly it prompts for Chapter Number twice on
        ;; new file and once for each capture.

        ;;  ${title} is the first thing that Org-roam is prompting you for (Node is the prompt i see), so
        ;;  when the capture triggers this is the bit that I want to get typed
        ;;  out as close to me thinking about it as possible. E.g. I really
        ;;  like this chapter, the examples are great.

        plain "* %T ${title}\n%?"
        :if-new ( file+head
                  "Books/Learning-CFEngine/${Chapter Number}.org"
                  "#+title: ${Chapter Number} - ${Chapter Title}" )

        ;; Some of my capture template attempts didn't work out well ...

        ;; This doesn't work. %\1 gets expanded as %^A plain "* %T
        ;; ${title}\n%?" :if-new ( file+head "Books/Learning-CFEngine/${Chapter
        ;; Number}.org" "#+title: %\1 - ${Chapter Title}" )

        ;; This expands to nothing for the filename and I end up with .org
        ;; file' plain "* %T ${title}\n%?" :if-new ( file+head
        ;; "Books/Learning-CFEngine/%\1.org" "#+title: ${Chapter Number} -
        ;; ${Chapter Title}" )

        ;; This errors out if: Wrong type argument: stringp, nil plain "* %T
        ;; ${title}\n%?" :if-new ( file+head "Books/Learning-CFEngine/%\\1.org"
        ;; "#+title: ${Chapter Number} - ${Chapter Title}" )

        :immediate-finish t
        :jump-to-captured t)

      )
)

If I was willing to spend a bit more time setting up and maintaining captures then I might instead have something like this:

(setq org-roam-capture-templates
      '(

        ;; This is just a default category which is the org-roam default if you
        ;; don't setup multiple templates.
        ( "d" "default"
          plain "%?"
          :if-new (file+head
                   "%<%Y%m%d%H%M%S>-${slug}.org"
                   "#+title: ${title}\n")
          :unnarrowed t)

        ;; Books
        ( "b" "Books" )

        ( "bc" "Learning CFEngine" )

        ( "bcp" "Preface"
          plain "* %T ${title}\n%?"
          :if-new ( file+head
                    "Books/Learning-CFEngine/Preface.org"
                    "#+title: Learning CFEngine - Preface" )
          :immediate-finish t
          :jump-to-captured nil)

        ( "bc1" "Chapter 01 - Introduction"
          plain "* %T ${title}\n%?"
          :if-new ( file+head
                    "Books/Learning-CFEngine/01.org"
                    "#+title: Learning CFEngine - 01 - Introduction" )
          :immediate-finish t
          :jump-to-captured nil )

        ( "bc2" "Chapter 02 - Getting Started with CFEngine"
          plain "* %T ${title}\n%?"
          :if-new ( file+head
                    "Books/Learning-CFEngine/02-Getting_Started_with_CFEngine.org"
                    "#+title: Learning CFEngine - 02 - Getting Started with CFEngine" )
          :immediate-finish t
          :jump-to-captured nil )

        ( "bc3" "Chapter 03 - CFEngine Basics"
          plain "* %T ${title}\n%?"
          :if-new ( file+head
                    "Books/Learning-CFEngine/03-CFEngine_Basics.org"
                    "#+title: Learning CFEngine 03 - CFEngine Basics" )
          :immediate-finish t
          :jump-to-captured nil )

        )
      )
)

When I initiate org-roam-capture I am prompted for Node. I type my most immediate thought, for example “One of my favorite quotes” and hit enter.

I am shown a menu where I can select a template.

Select a capture template
=========================

[d]     default
[b]...  Books...
-----------------------------------------------------------------------------
[C]     Customize org-capture-templates
[q]     Abort

I select b for Books and I am taken to the Books sub-menu.

Select a capture template
=========================

b [c]      Learning CFEngine...
-----------------------------------------------------------------------------
[C]     Customize org-capture-templates
[q]     Abort

I press c for Learning CFEngine and I am presented with a prompt to select the chapter.

Select a capture template
=========================

b [c]      Learning CFEngine...
-----------------------------------------------------------------------------
[C]     Customize org-capture-templates
[q]     Abort

And then when I initiate a capture.

Select a capture template
=========================

bc [p]     Preface
bc [1]     Chapter 01 - Introduction
bc [2]     Chapter 02 - Getting Started with CFEngine
bc [3]     Chapter 03 - CFEngine Basics
-----------------------------------------------------------------------------
[C]     Customize org-capture-templates
[q]     Abort

I select 1 for Chapter 1 and am prompted with the capture template to record my thoughts.

* 2022-11-12 Sat 14:45 One of my favorite quotes
<Insertion point here>

After I fill in whatever I want, I save it, the file looks like this:

cat ~/org/roam/Books/Learning-CFEngine/01.org
:PROPERTIES:
:ID:       bcf34856-ddba-45a3-8026-e73d0347385b
:END:
#+title: Learning CFEngine - 01 - Introduction
* <2022-11-12 Sat 14:45> One of my favorite quotes
:PROPERTIES:
:CREATED:  [2022-11-12 Sat 14:45]
:ID:       3071be3c-aa5a-4c7f-ac6a-06a4dc6b334e
:END:

#+caption: Mark Burgess, author of CFEngine
#+begin_quote
Every time someone logs onto a system by hand, they jeopardize
everyone’s understanding of the system.
#+end_quote

You mentioned reading the book for a class. So I might have one or more capture templates for the class. Probably I’d have at least one daily capture for a class meeting. I would take notes from the class in a file specific for that day. The template includes a link to the single file for the class (I call it training here).

(setq org-roam-dailies-capture-templates
      `(
        ( "m" "Meetings" )
        ( "mt" "Training" )
        ( "mtc" "CFEngine - ACME Corp. - 2022-11-15"
          entry
         "* %?"
         :if-new (file+head ,(expand-file-name "meetings/training/CFEngine/ACME_Corp_2022-11-15/%<%Y-%m-%d>.org" org-roam-dailies-directory)
                            ":properties:\n:Training: [[id:165577da-3547-4671-8789-9b3e06dbfe7f][CFEngine Training - ACME Corp - 2022-11-15]]\n:end:#+title: CFEngine - ACME Corp. %<%A, %B %d %Y>\n")
         :clock-in nil
         :clock-resume nil
         )
))

Then I have a couple more capture templates for the training. Once for assignments which makes TODO entries and one for Edit which just takes me to the file for editing anything.

(setq org-roam-capture-templates
      '(

        ;; This is just a default category which is the org-roam default if you
        ;; don't setup multiple templates.
        ( "d" "default"
          plain "%?"
          :if-new (file+head
                   "%<%Y%m%d%H%M%S>-${slug}.org"
                   "#+title: ${title}\n")
          :unnarrowed t)

        ( "t" "training" )
        ( "tc" "CFEngine" )
        ( "tca" "ACME Corp - 2022-11-15" )
        ( "tcaa" "Assignment"
          entry
          "* TODO ${title}\nDEADLINE: %^{DEADLINE}t SCHEDULED: %t\n:properties:\n:prior-context: %a\n:end:"
          :if-new (file+head
                   "training/cfengine/2022-11-15_ACME_Corp.org"
                   "#+title: CFEngine Training - ACME Corp - 2022-11-15")
          )

        ("tcae" "Edit"
         plain
         "%?"
          :if-new (file+head
                   "training/cfengine/2022-11-15_ACME_Corp.org"
                   "#+title: CFEngine Training - ACME Corp - 2022-11-15")
         :immediate-finish t
         :junp-to-captured t
         :unnarrowed t

         )



        ;; Books
        ( "b" "Books" )

        ( "bc" "Learning CFEngine" )

                    ( "bcr" "Review"
            plain "* %T ${title}\n%?"
            :if-new ( file+head
                      "Books/Learning-CFEngine/Review.org"
                      ":PROPERTIES:\n:ID: book-learning-cfengine-3-review\n:END:\n#+title: Learning CFEngine - Review\n" )
            :immediate-finish t
            :jump-to-captured nil)


        ( "bcp" "Preface"
          plain "* %T ${title}\n%?"
          :if-new ( file+head
                    "Books/Learning-CFEngine/Preface.org"
                    ":PROPERTIES:\n:REVIEW: [[id:book-learning-cfengine-3-review][Review]]\n:END:\n#+title: Learning CFEngine - Preface\n" )
          :immediate-finish t
          :jump-to-captured nil)

        ( "bc1" "Chapter 01 - Introduction"
          plain "* %T ${title}\n%?"
          :if-new ( file+head
                    "Books/Learning-CFEngine/01.org"
                    ":PROPERTIES:\n:REVIEW: [[id:book-learning-cfengine-3-review][Review]]\n:END:\n#+title: Learning CFEngine - 01 - Introduction\n" )
          :immediate-finish t
          :jump-to-captured nil )

        ( "bc2" "Chapter 02 - Getting Started with CFEngine"
          plain "* %T ${title}\n%?"
          :if-new ( file+head
                    "Books/Learning-CFEngine/02-Getting_Started_with_CFEngine.org"
                    ":PROPERTIES:\n:REVIEW: [[id:book-learning-cfengine-3-review][Review]]\n:END:\n#+title: Learning CFEngine - 02 - Getting Started with CFEngine\n" )
          :immediate-finish t
          :jump-to-captured nil )

        ( "bc3" "Chapter 03 - CFEngine Basics"
          plain "* %T ${title}\n%?"
          :if-new ( file+head
                    "Books/Learning-CFEngine/03-CFEngine_Basics.org"
                    ":PROPERTIES:\n:REVIEW: [[id:book-learning-cfengine-3-review][Review]]\n:END:\n#+title: Learning CFEngine 03 - CFEngine Basics\n" )
          :immediate-finish t
          :jump-to-captured nil )

        )
      )
)
for each in $(find ~/org/roam/training/cfengine/2022-11-15_ACME_Corp.org -type f); do echo "$each"; cat $each; done
for each in $(find ~/org/roam/Books/Learning-CFEngine/ -type f); do echo "$each"; cat $each; done
for each in $(find ~/org/roam/daily/meetings/training/CFEngine/ACME_Corp_2022-11-15/ -type f); do echo "$each"; cat $each; done
/home/nickanderson/org/roam/training/cfengine/2022-11-15_ACME_Corp.org
:PROPERTIES:
:ID:       165577da-3547-4671-8789-9b3e06dbfe7f
:END:
#+title: CFEngine Training - ACME Corp - 2022-11-15

* TODO Read chapter 1 of Learning CFEngine                           :ATTACH:
DEADLINE: <2022-11-15 Tue> SCHEDULED: <2022-11-13 Sun>
:PROPERTIES:
:ID:       fa4d4582-d2b6-49b0-8bbe-23c4d1c6ad7c
:END:
:properties:
:prior-context: [[id:944564f7-27c0-45f7-9fc4-73278a236d80][We are supposed to read the first chapter of Learning CFEngine 3 before training]]
:end:

[[id:bcf34856-ddba-45a3-8026-e73d0347385b][Learning CFEngine - 01 - Introduction]]
/home/nickanderson/org/roam/Books/Learning-CFEngine/Review.org
:PROPERTIES:
:ID:       book-learning-cfengine-3-review
:END:
#+title: Learning CFEngine - Review
* <2022-11-13 Sun 13:17> TLDR loved it

/home/nickanderson/org/roam/Books/Learning-CFEngine/01.org
:PROPERTIES:
:ID:       bcf34856-ddba-45a3-8026-e73d0347385b
:review: [[id:book-learning-cfengine-3-review][Review]]
:END:
#+title: Learning CFEngine - 01 - Introduction

* <2022-11-12 Sat 14:45> One of my favorite quotes
:PROPERTIES:
:CREATED:  [2022-11-12 Sat 14:45]
:ID:       3071be3c-aa5a-4c7f-ac6a-06a4dc6b334e
:END:

#+caption: Mark Burgess, author of CFEngine
#+begin_quote
Every time someone logs onto a system by hand, they jeopardize
everyone’s understanding of the system.
#+end_quote
/home/nickanderson/org/roam/daily/meetings/training/CFEngine/ACME_Corp_2022-11-15/2022-11-13.org
:PROPERTIES:
:ID:       b7755247-9649-4058-8997-12ccd24fe04a
:Training: [[id:165577da-3547-4671-8789-9b3e06dbfe7f][CFEngine Training - ACME Corp - 2022-11-15]]
:END:
#+title: CFEngine - ACME Corp. Sunday, November 13 2022
* We are supposed to read the first chapter of Learning CFEngine 3 before training
:PROPERTIES:
:ID:       944564f7-27c0-45f7-9fc4-73278a236d80
:END:

[[id:fa4d4582-d2b6-49b0-8bbe-23c4d1c6ad7c][Read chapter 1 of Learning CFEngine]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment