Display a Random Inspiring Quote for Journaling or Shell Prompts

The odd title gives it away – I don’t have a good use-case for this :)

Dr. Drang shared how he displayed one random line of “Oblique Strategies” in his email signatures many years ago.

The “Oblique Strategies” can be found here: http://www.rtqe.net/ObliqueStrategies/Edition1-3.html

They look like this:

Abandon normal instruments
Accept advice
A line has two sides
Allow an easement (an easement is the abandonment of a stricture)
Always first steps

“Fortunes” or inspirational “quotes for thought” can work as journaling prompts. It’s also possible to start a new shell session with this “fortune cookie” format as a greeting or Message of the Day.

I’ve formatted the file thus:

  • Treat # at the beginning of a line to be a comment (referencing the source(s))
  • Assuming ~/fortunes.txt as the location

Bash script, e.g. for MotD updates

Bash is simple. Filter out comments, then use shuf to get 1 random line:

$ grep -e "^[^#]" ~/fortunes.txt | shuf -n 1

That prints any line from the file. Easy. Use cron to replace the Message of the Day in /etc/motd and then you have an inspirational greeting in the shell.

Elisp random fortune function for journaling

To get a random prompt in my Emacs org-mode journaling templates was a bit more involved. Instead of piping in the shell, I’m using “the Emacs way”, i.e. applying modifications to invisible, temporary buffers with the file contents:

(defun ct/random-fortune (&optional file)
  "From a fortunes file, produce a random line.
Prints the line to the minibuffer when called interactively,
returns the line otherwise.

When FILE is not nil, read that file. Otherwise, defaults to '~/fortunes.txt'.
Ignores lines that start with a hash \"#\"."
  (let (($random-line (with-temp-buffer
                        (insert-file-contents "~/fortunes.txt")
                        (keep-lines "^[^#]")
                        (goto-line (1+ (random (count-lines (point-min) (point-max)))))
                        (buffer-substring-no-properties (line-beginning-position) (line-end-position)))))
    ;; 22.4 Distinguish Interactive Calls <https://www.gnu.org/software/emacs/manual/html_node/elisp/Distinguish-Interactive.html>
    (if (called-interactively-p 'any)
        (message "%s" $random-line)

This either “"”inspires””” me interactively, by showing the line at the bottom of the window, or when called programmatically, it returns the string for insertion into the meditative journaling template.

That all presupposes I actually have such a template or perform a practice like this, but in reality, this was just a short and fun thing to do between holidays, really.

Maybe your journaling practice benefits from this, though!

Receive new .