= Gopher Logging in Eleven Lines of Shell =

Writing today's entry is a bit tricky because I'm writing it with
the help of the very thing I'm writing about; describing the
thing with the thing.  It feels a little like "Drawing Hands",
the MC Escher lithograph where a pair of hands draws each other
into existance.

As the title suggests, I finally broke down and scripted these
phlog entries using a shell script.  I've always said "make
the computer do the work", but I often get myself into trouble
by putting the cart before the horse: inventing automation for
things I haven't done yet even once manually.  Not this time;
I waited until I had a whole three entries under my belt before
having my first go at automation.

A whole three!  I'm practically an old hand, now.

Further, I practiced great restraint in the automation.
In fact, I turned the restraint into a bit of a challenge:
just how *little* programming would yield a phlog entry generator?

So here are the eleven lines:

  today.sh
------------------------------------------------------------------
	#!/bin/sh
	title=$1
	date=$(date +%Y-%m-%d)
	fname="$date-$(echo "$title" | tr ' ' '-')"
	srcpath="src/phlog/$fname"
	if [ ! -f $srcpath ]; then echo "= $title =" >> $srcpath; fi
	vim $srcpath
	sed "s/<phlog_updated>/$date/" src/gophermap > publish/goph...
	fmt -w67 $srcpath > publish/phlog/$fname
	scp publish/gophermap $sdf:gopher/
	scp publish/phlog/$fname $sdf:gopher/phlog/
------------------------------------------------------------------

To create this entry, I typed (let's see...CTRL-Z...)

	$ ./today.sh "Gopher Logging in Eleven Lines of Shell"

Which created the file you're now reading and wrote the title at
the top.  As soon as I finish editing this, it will pass the file
through 'fmt' to reflow the paragraphs to a mainframe-worthy 67
columns, and then upload the result to my Gopher space on SDF.org.

The neat bit, as you may have noticed above, is that I have also
turned my gophermap file into an ad-hoc template by putting a
placeholder on this line:

	Last updated: <phlog_updated>

Which is replaced by the 'sed' command with the current date.
The new gophermap is also written and uploaded.

It was quick and practically effortless.  Shell scripts would
suck if they weren't so insanely productive.

Here's what the structure looks like:

	dave@wizard~/d/proj/sdf/gopher$ tree
	.
	├── publish
	│   ├── gophermap
	│   └── phlog
	│       ├── 2018-08-09-First-Post
	│       ├── 2018-08-10-The-Logging-Habit
	│       └── 2018-08-12-Weekend-Tech-Scramble
	├── src
	│   ├── gophermap
	│   └── phlog
	│       ├── 2018-08-09-First-Post
	│       ├── 2018-08-10-The-Logging-Habit
	│       ├── 2018-08-12-Weekend-Tech-Scramble
	│       └── 2018-08-13-Gopher-Logging-in-Elev...
	└── today.sh

	4 directories, 10 files

As soon as I save this, the new entry will end up in the publish/
directory with the rest.

I doubt my Gopher software will remain a mere eleven lines for
long.  But for now, I'm reveling in the minimalism.  I'll try
to hold off on complexity for as long as I can.

Oh, and I must add that I would absolutely be using 'rsync', but
it turns out that you have to be a MetaARPA member on SDF to have
permission to use it.  Thus the two 'scp' calls.  I could use 'scp
-r' to recursively copy everything in publish/, but that would
just be wasteful, especially when I get more content up here.

			    *	*   *

It was very nice meeting some of you on IRC (irc.sdf.org) on
the #gopher channel.

This is a very warm little community so far and I feel very much
at home here in my little burrow.

Good night my fellow rodents!


			    *	*   *

Next morning update: Naturally there was a mistake in one of the
"eleven lines" and my script happily published the *unformatted*
version of the entry.  My appologies to anyone who tried to
read it and found the text flowing off the screen.  I knew I
should have tested it, but it was late at night...which led to
bad descisions...which is why I have a strict policy about not
doing critical things when I am tired.	I've corrected the script
(and the copy of it above).  We'll see if I got it right when
I push out today's entry. :-)