[comp.mail.mh] Showing the first message in a sequence

benson@odi.UUCP (Benson Margulies) (04/25/89)

I wanted a way to show the first unseen message in a folder.
In desperation, I came up with the following. Surely there
is a better way. Perhaps someone could clue me in?

#! /bin/csh
# show the next message unseen in the folder. For now, this just
# works in the curent folder, because the arg parsing is too hard.
set unseen = ( `pick unseen` )
show $* $unseen[1]
-- 
Benson I. Margulies

mcgrew@ichthous.Sun.COM (Darin McGrew) (04/27/89)

In article <306@odi.UUCP>
odi!benson@talcott.harvard.edu (Benson Margulies) writes:
>I wanted a way to show the first unseen message in a folder...

Here is my ~/bin/first script.  It uses a feature in MH 6.5
pick; if -list is specified, and nothing matches, the pick
command prints "0" so that other MH commands won't use their
default message sequence.  It also does all sorts of things
to be MH-like.

My script is basically the same as yours, except that it
passes options to pick instead of passing options to show.
This allows you to specify other folders besides the current
folder, and all sorts of other things like that.

Darin McGrew		mcgrew@Sun.COM

------------------------- cut here -------------------------
#!/bin/sh
CMD=`basename $0`
unseen="`sed -n '/Unseen-Sequence: */s///p' $HOME/.mh_profile`"
USAGE="syntax: $CMD [+folder] [msgs] [switches]
  msgs		default is '$unseen'; must precede any switches
  switches	see pick(1):
"

#
# Do we show the first or the last match?
#
case "$CMD" in
first)	which=head;;
last)	which=tail;;
*)	echo "$CMD: must be invoked as 'first' or as 'last'" >&2
	exit 1;;
esac

#
# Do we need to specify the unseen sequence?
#
for i
do
	case "$i" in
	-help)	echo "$USAGE" >&2
		pick -help >&2
		exit 0;;
	-*)	break;;
	+*)	;;
	*)	unseen=;;
	esac
done

#
# Show the first matching message
#
show `pick -list $unseen "$@" | $which -1`
------------------------- cut here -------------------------

jromine@tertius.ics.uci.edu (John Romine) (04/28/89)

In article <306@odi.UUCP> (Benson Margulies) writes:
>I wanted a way to show the first unseen message in a folder.
>In desperation, I came up with the following. Surely there
>is a better way. Perhaps someone could clue me in?

Sorry, not at the moment.  Right now, you can use modifiers on
"official" sequences ("first", "last", etc.) so you can say something
like "scan first:10" to scan the first ten messages.  I always thought
we should accept those modifiers on user-defined sequence names as well.
I'll probably work on that if I can find the time.

--
John Romine	ucbvax!ucivax!jromine, jromine@ics.uci.edu
UCI ICS Dept.

milne@ics.uci.edu (Alastair Milne) (05/06/89)

John Romine <jromine@tertius.ics.uci.edu> writes
>In article <306@odi.UUCP> (Benson Margulies) writes:
>>I wanted a way to show the first unseen message in a folder.
>
>...Right now, you can use modifiers on
>"official" sequences ("first", "last", etc.) so you can say something
>like "scan first:10" to scan the first ten messages.  I always thought
>we should accept those modifiers on user-defined sequence names as well.

    What you really want is some recursive application of sequence specifiers,
    so that the sequence resulting from each can have a further sequence
    extracted from it.

    Like:
	sc unseen:first
	sc unseen:first:2
	sc unseen:last:5
	sc unseen:first:10:last:3  -- ie the unseen ones starting at the 8th
					and ending with the 10th.

    I'm just using "unseen" as a well-known sequence name.  I see no reason
    this shouldn't apply to any arbitrary sequence.

    Alastair Milne,
    UCI

jdpeek@RODAN.ACS.SYR.EDU (Jerry Peek) (05/09/89)

In article <306@odi.UUCP> (Benson Margulies) writes:
>I wanted a way to show the first unseen message in a folder.

You can do it with the shell.  Here's a simple little Bourne-shell script
(call it "fu") that shows the first unseen message.
You could make it into a c-shell alias, if you want:


#! /bin/sh
# Use show(1) on first message in "unseen" sequence.  This is an ugly hack.
# Runs mhpath(1) to get full pathnames of all unseen messages; strips off
# everything except the message number from the first pathname.
show `mhpath unseen | sed -n '1s@.*/@@p'`


You could be more elegant.  And there's gotta be a better way.  Ideas, anybody?

--Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY
  jdpeek@rodan.acs.syr.edu, SUNRIS::JDPEEK, jdpeek@suvm.bitnet
  +1 315 443-3995