* David T-G <[EMAIL PROTECTED]> [2002-07-05 00:08]:
> In tcsh, as discussed on the list quite a while back, one can
> construct a command to complete mutt folders as shown in the attached
> snippet (I watched the ideas come across and saved all of the various
> flavors, so I have more than just one line).
> 
> Can the same thing be done in bash?  I see that bash also has a
> complete command but the man pages are a little obtuse and I can't
> tell if such delightful magic is possible.  I know that I sure miss it
> already, though!

Here's a simple bash function/complete pair that is a (good?) place to
begin.  I've only been using bash's programmable completion for a few
weeks, and I'm still pretty new at it.  The gist of it is, fill the
COMPREPLY array with the output of compgen; the trick is getting the
correct thing into COMPREPLY, of course.

There is a bug in here, somewhere; if you do mutt -f =mb<tab>, and have
a mailbox beginning with  mb, or course, it ends up with two ='s at the
beginning.  This doesn't happen if you define your lists with + and not
=, so there's probably something special about using = as a beginning
character.

Another fun thing this does is give a command-line arg summary unless
you are typing -f, in which case it gives you mailboxes.  A good
improvement would be that -a<tab>, -i<tab>, -F<tab>, and -H<tab> give
you file completions, and -c<tab> and -b<tab> give you email address
completions from your ~/.mail_aliases file.

Be sure to set MBOXLIST and MUTT appropriately, BTW.

  _mutt() {
    local MBOXLIST="$HOME/.mutt/lists"
    local MUTT=/usr/bin/mutt
    local mboxes cur prev
    mboxes=$(grep '^ *mailboxes' $MBOXLIST | sed -e "s/mailboxes//" | tr -d "\012")

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    if [[ "$prev" == -f ]]
    then
      COMPREPLY=( $(compgen -W "$mboxes" $cur) );
    else
      COMPREPLY=( $(compgen -W "$($MUTT -h | awk '/^ *\-/{printf "%s ", $1}')") )
    fi

    return 0;
  }

  complete -F _mutt -o default mutt

Good luck.

(darren)

-- 
It ain't those parts of the Bible that I can't understand that bother
me, it's the parts that I do understand.
    -- Mark Twain

Reply via email to