[comp.mail.mush] adding a Keywords: header to message

daniel@island.COM (Daniel Smith - part of the caffeine generation) (06/03/91)

	This is a first pass at a cmd and a couple of short scripts
that allow you to add a Keywords: header to a message.  Presumably
you would later do a search through many messages looking for a match.

	The cmd is:

cmd	keyword 'sh echo \!* > $HOME/.keyargs; \
		source $HOME/lib/mush_add_keyword'

	The mush_add_keyword script is:

#
#	mush_add_keyword - add a Keywords: header to a mail message
#
#	Daniel Smith, daniel@island.com, June 2, 1991
#
#	this gets called from a cmd in mush, which should look like:
#
#	cmd	keyword 'sh echo \!* > $HOME/.keyargs; \
#		source $HOME/lib/mush_add_keyword'

set holdedit=$editor
set editor=$HOME/lib/mush_keyword.sh
edit
set editor=$holdedit

	and finally, the mush_keyword.sh script is:

#! /bin/sh
#
#	mush_keyword.sh - add a keyword line to message

cat << +++ > $HOME/.keysed
/From /,/^$/ {
	/Subject:/a\\
Keywords: `cat $HOME/.keyargs`
}
+++
sed -f $HOME/.keysed $1 > $1.tmp
mv -f $1.tmp $1


	Some notes on all of this:

	I didn't want to have a cmd that rambled on forever, so I had
it source a mush script (mush_add_keyword).  A problem I ran into
was setting a variable to \!* and passing that to the script.  I had
to resort to echo'ing the args to a file and later using that.  Is
there a better way?

	I wasn't sure if I could shove the functionality of mush_keyword.sh
into the mush script.  It was a first pass, but as it turns out, I now have
a simple tool to add a Keywords: line to an arbitrary file.

	mush_keyword.sh should append keywords to a file that already
has a Keywords: line, rather than starting a new one.  I just didn't
want to get into this yet, but it would be a few lines in sed (also,
being careful to scan and change only the mail header, a Keywords:
line in the body of the message should remain untouched).

	This all works off the fact that you can change the editor
variable to point at your own script, so I thank Dan and Bart for that
bit of foresight :-)

	This really should be in perl, but I was in a hurry and wanted
to put the idea out there that would work on all machines.  On the
other hand, sites that have installed mush are very likely to have
perl going too...

	Typical usage from within mush:

	keyword edit, script, sed

	(would add the line "Keywords edit, script, sed" to the current
	message)

	A helpful cmd for later finding messages with given keywords:

	cmd pk 'pick Keywords:.*\!*.*'

	Perhaps a useful extension would be the ability to add the
same set of keywords to a range of messages.  Improvements very
much welcome.  Enjoy!

				Daniel
-- 
daniel@island.com       Daniel Smith, Island Graphics, (415) 491 0765 x 250(w)
daniel@world.std.com      4000 CivicCenterDrive SanRafael MarinCounty CA 94903
dansmith@well.sf.ca.us      Fax: 491 0402 Disclaimer: Hey, I wrote it, not IG!
falling/yes I'm falling/and she keeps calling/me back again - IJSaF, Beatles