On phlogosphere.org, the [ph|g]logs are marked with a timestamp, coming from
the modification date of the user's gopher directory. glog.sh is now honouring
this. Here's the updated version:

#!/bin/sh
# gopherlog - GPL - (C)2005 Yargo C Bonetti
cvsid="\$Id: glog.sh,v 1.12 2009/12/18 13:01:45 yargo Exp $"
progname=`basename $0`
# default dir for storing messages
rootdir=${GLOG_ROOT:-$HOME/gopher/glog}
# place to touch for timestamp updating
touchspot=${GLOG_TOUCH:-$HOME/gopher/}
# default prefix for messages
prefix=${GLOG_PREFIX:-g}
# automatic entry id
autoid=$prefix`date -u +%y%j%H%M`
# reporting file for last message
lastmsg=$rootdir/actmsg.txt
# map file
map='gophermap'
# separation for map headers and glog entries; will be used as pattern
separator="     -----"
# information attached to new file
newinfo="::: reply via mailto:[email protected]?Subject=$autoid"
# default message suffix
suffix='.txt'

# error display routine
err () { echo $progname error: "$*" >&2 ; }
# exit routine in case of signal
abort () {
echo "aborted - if interactive, hit CTRL-D" >&2
cat >>$HOME/dead.$progname
cleanexit 9
}
trap abort HUP INT QUIT ABRT PIPE TERM

# help display
usage () { cat <<EOH >&2 ; }
gopher log script 2005 YCB - $cvsid
usage: $progname [-a|b|h] [-p prefix] [-q suffix] [-r root] [-s subject] [id]
will add a message entered via stdin to a directory, named with a time-stamp
and add a link in $map after its header and before old links
(header ends at line containing '$separator')

-a     only allow appending to existing file (id is required in this case)
-b     ignore inline commands in stdin
-h     this help
-p,-q  message prefix (default: $prefix) and suffix (default: $suffix)
-r     root directory (default: $rootdir)
       a copy of the last message is put into $lastmsg
-s     subject - if missing, first line of stdin will be used
id     if present, entry will be added to message id

inline edit commands, must be given at beginning of line:
.e     edit message entered so far with \$EDITOR (currently $EDITOR)
.h     short command help
.p     print message entered so far
.q     abort message
.s     enter new subject
.      end message
EOH

echo "($progname - for help, use option -h)" >&2

while test "$1" != "" ; do
case $1 in
-a) append=1 ; echo appending only >&2 ;;
-b) ign=1 ; echo ignoring inline commands >&2 ;;
-h|--help) usage ; exit 3 ;;
-p) shift ; prefix="$1" ; echo prefix: $prefix >&2 ;;
-q) shift ; suffix="$1" ; echo suffix: $suffix >&2 ;;
-r) shift ; rootdir="$1" ; echo root directory: $rootdir >&2 ;;
-s) shift ; subject="$1" ; echo "subject: $subject" >&2 ;;
-*) err "ignoring unknown option $1" ;;
 *) id="${1%.*}" ;; # remove suffix if present
esac
shift
done

test -d $rootdir || {
err "nonexistent root directory $rootdir"
usage
exit 7
}

# lock-&buffer-file
tmpfile=$rootdir/$progname-lock
if test -f $tmpfile ; then
err "$tmpfile exists, waiting for disappearing..."
sleep 5
if test -f $tmpfile ; then
 err "$tmpfile exists, other instance may be running"
 exit 8
fi
fi
# exit routine for cleanup
cleanexit () { rm -f $tmpfile ; exit $1 ; }

id=${id:-$autoid}
echo id: $id >&2

#generate file name and check
lfile=$rootdir/${id}$suffix
if test ! -f $lfile ; then
if test "$append" = "1" ; then
err $lfile nonexistent but append-only
cleanexit 6
fi
else
# if file exists already, do not append information
newinfo=''
fi

: >$tmpfile # clear tmpfile
# add subject as first line, if defined
if test "$subject" != "" ; then echo "$subject" >$tmpfile ; fi

if test "$ign" = "1" ; then
# simply take contents of tmpfile and stdin into message file
cat >>$tmpfile
# fold lines to width of 77 characters max (not necessary in lastmsg)
fold -s -w 77 $tmpfile >>$lfile
# and store in lastmsg together with id
echo "#$id" >$lastmsg
cat $tmpfile >>$lastmsg
else
# process one line at a time after printing of header
cat $tmpfile
while read mline ; do
 case $mline in
 .e) test -x $EDITOR && $EDITOR $tmpfile ;;
 .p) echo "subject: $subject" ; cat $tmpfile ;;
 .q) err aborted ; cleanexit 1 ;;
 .s) echo "enter new subject" ; echo " currently: $subject"
     read newsubject ; subject=${newsubject:-$subject} ;;
 .) break ;;
 .*) echo "commands: .e edit .p print .q abort .s subject . end" ;;
 *) echo "$mline" >>$tmpfile ;;
 esac
done
# ignore messages shorter than 7 words or 1 line (noise)
wc $tmpfile | { read tl tw rem ; test $tw -gt 6 -a $tl -gt 1 ; } ||
 { err "message too short" ; cleanexit 2 ; }
# append message to logfile and store in lastmsg
cat $tmpfile >>$lfile
echo "#$id" >$lastmsg
cat $tmpfile >>$lastmsg
fi
echo >>$lfile
echo ':::' `date -u` >>$lfile
echo "$newinfo" >>$lfile
echo "$separator" >>$lfile
echo >>$lfile
# update timestamp
touch $touchspot

# update map file if it is writable and if current id not yet linked
map=$rootdir/$map
if ! grep "${id}$suffix" $map >/dev/null 2>&1 &&
  test -f $map -a -w $map ; then
# set subject, just first line if not yet defined
subject=${subject:-`head -n 1 $tmpfile`}
# create gophermap entry
mapentry="0$subject [$id]      ./${id}$suffix"
# if separator present in map file
if grep "$separator" $map 2>&1 >/dev/null
then
# get map headers
 sed -e "/$separator/,\$d" $map >$tmpfile
 echo "$separator" >>$tmpfile
 echo "$mapentry" >>$tmpfile
# get rest of map
 sed -e "1,/$separator/d" $map >>$tmpfile
else
# just prepend to map file
 echo "$mapentry" >$tmpfile
 cat $map >>$tmpfile
fi
# write new map
cat $tmpfile >$map
fi

# make sure everybody can read it
# map file, if present, should already have correct permissions!
chmod a+r $lfile $lastmsg
cleanexit 0

::: Fri Dec 18 13:07:39 UTC 2009
::: reply via mailto:[email protected]?Subject=g093521303
    -----