I write every day. Every day, I write. I have a quota of words to fill, and after each sleep session, I sit in front of my keyboard and begin typing.
I used to use Emacs for this—the One True Editor. Yet, it has one flaw that disrupted my writing routine: it has too many features. When I encountered writer’s block or an idea I couldn’t quite articulate, I would start tinkering with the editor instead. Emacs is like a friend, and one should keep friends away from the workplace; otherwise, no work gets done.
For this reason, I began writing with ed some time ago. ed is not my friend; it’s the standard editor. It’s also the grandfather of vi, but fathers should not bear the vices of their sons.
Note from 2024: Ten years after writing this post, I’m editing it with Neovim, the grandson of all these tools.
ed was very nice to write with. It doesn’t have many features. It prints a 0 when it opens, I type i to insert text, and then I write whatever I like. When I put a lonely . on a line, it understands that I’ve finished my words. Then, with w, I save the file to disk and see its length—length in bytes, as every true writer nowadays should know.
ed is minimal, and while I occasionally get frustrated by its modal behavior, that’s exactly why I was happy to write with it.
However, I eventually decided that even pressing those few command keys was too much. i, ., and w—one can forget them easily. And it seemed I had a tendency to learn more of its commands, which are passed down to its grandchildren. God save us from the vices of vi.
Then, I decided to concoct a script that uses cat. Everyone knows writers like cats, and I like cat too; it concatenates text into files and is also used to print their content. It’s much simpler than ed—much simpler. It is not an ambiguous dork like ed; it’s a simple animal that writes into files whatever I type into it.
It was easy to check the file size in words after I finished. I wrote a while loop to continue until I reached my daily quota. The script creates a new file, adds an Org-mode header, and includes the contents of the clipboard just after the title so I can include notes. cat exits with Ctrl-D, and when it finishes, the script checks the word count. If I’m still short of my daily target, it appends a ----- separator and opens the file again. You have to finish your words, whether your brain bleeds or your cat dies.
The effect? I began using it today, so I’m still not sure about the long-term impact, but there’s certainly nothing to distract me. When I used Emacs, the info pages were highly entertaining—I was just finishing the command-line options of GNU Backgammon when I decided to switch. Modern programs are so customizable that I can’t even finish reading their manuals.
The script is shown below. It asks for a filename; if you don’t provide one, it creates one based on the date. It has some minor changes from the version I use, as I tend to name my files differently and I haven’t tested this specific version thoroughly, but here it is. Copy and paste it into a file named write-with-cat, make it executable with chmod +x write-with-cat, and run it. You’ll need a Unix-like system (even my mom uses Debian, you know).
The second part of the script, which I’ve commented out, copies the written material to a repository and commits it using Mercurial.
#!/bin/bash
WORDSIZE=600
echo "Please set a (tentative) name?"
read response
if [ -z "$response" ] ; then
dirname=work-`date +%y-%m-%d`-$RANDOM
else
dirname=work-${response}
fi
tempdirname="/tmp/$dirname"
mkdir $tempdirname
docname="$tempdirname/index.org"
selection=`xsel -ob`
cat > $docname <<EOF
#+TITLE: $response
#+AUTHOR:
#+DATE: `date`
$selection
EOF
clear
cat $docname
while [ `wc -w "$docname" | cut -f 1 -d ' '` -le $WORDSIZE ] ; do
cat >> $docname
echo "\n-----" >> "$docname"
wc -w "$docname"
done