On 2002.01.04, in <[EMAIL PROTECTED]>,
        "Rob 'Feztaa' Park" <[EMAIL PROTECTED]> wrote:
> Alas! Cameron Simpson spake thus:
> > | I'm pretty sure I've seen this done somewhere, but I can't find it.
> > 
> > Well, it's indirect, but you could wrap mutt in a script which said:
> > 
> >     #!/bin/sh
> >     ( cd $HOME/mail
> >       when=`date +%Y-%m`
> >       for mbox in *
> >       do  echo "mbox-hook =$mbox \"=archives/$when-$mbox\""
> >       done >$HOME/.muttrc-auto
> >     )
> >     exec real-mutt-program ${1+"$@"}
> > 
> > and just source .muttrc-auto from .muttrc. Ugly but would work.
> 
> Interesting idea. I'm sure I've seen a better way to do it, though.
> Perhaps I'll have to search the archives :)

I'm into overkill today.

You could put that in a script such as the one I've attached, and run
it from .muttrc like this:

source `$HOME/bin/mutt-prep folders=$HOME/mail`

This approach lets your mutt-prep script write anything muttrc-ish on
its stdout, and mutt will absorb it with no shell wrappers. The cmdline
eval lets your source line configure the script's parameters easily.
(You could do it with prefixed variables or /bin/env, but this makes
them local instead of environmental, fwiw, and it might be easier to
read.)

It's fundamentally the same idea, but you don't have to mess with
wrappers, at least. It feels a little neater, in some way I can't
explain.

-- 
 -D.    [EMAIL PROTECTED]        NSIT    University of Chicago
#!/bin/sh
##
## This emits muttrc commands on stdout. call it with
##      source `/path/to/mutt-prep`
## in your .muttrc file.
##

## Set variables from cmdline.
eval "$@"

## Set defaults -- these can be overridden on the cmdline.
file=${file-$HOME/.mutt-runtime}
folders=${folders-$HOME/Mail}

## All output goes to $file. echo the filename first, so mutt can source it.
echo "$file"
exec >"$file"

## Set mbox-hooks.
when=`date +%Y-%m`
(cd "$folders"
 ls | sed -e 's#\(.*\)#mbox-hook =\1 "=archives/\1-'$when'"#'
)

## Set mailboxes (could be merged above).
(cd "$folders"
 ls | sed -e 's#\(.*\)#mailboxes =\1#'
)

## Something to source an rc file if present.
try_source () {
        for rc in "$@"; do
                if [ -f $HOME/.mutt-$rc ]; then
                        echo "source $HOME/.mutt-$rc"
                fi
        done
}

## Source an NNTP config file if mutt has NNTP support.
if mutt -v | grep NNTP >/dev/null; then
        try_source nntp
fi

## Source a muttrc for this host or domain, if one exists.
try_source `hostname` `sed -e '1s/.* //;q' /etc/resolv.conf`

## Dynamically convert my pine addressbook to mutt format.
if [ -f $HOME/.addressbook ]; then
    cat $HOME/.addressbook \
    | awk '-F   ' '/^[^ ]/{printf("alias %-20.20s %s <%s>\n", $1, $2, $3);}'
    #        ^^^ that's a tab character
fi

## Add other runtime tasks as you like.

Reply via email to