I've banged together a (reasonably) complete version of the completion
stuff for bash that David T-G asked about earlier. It's attached. The
only thing that doesn't seem to work for me is getting aliases from
~/.mutt/aliases (the commented out awk piece); the awk script works from
the command line but goes into an infinite loop within the _mutt
function.
If anyone decides to try to use this, be sure to set $MBOXLISTS and
$MUTT to correct values for your setup, of course.
I'll look into donating it to tbe Bash Programmable Completion project
next week.
(darren)
--
We protest things because we are too impotent to effect change. We
effect change through positive action, not simply through
demonstrations of intent.
# vim: set ft=sh:
_mutt() {
local MBOXLIST="$HOME/.mutt/lists"
local MUTT="/usr/bin/mutt"
local ALIASES="$HOME/.mutt/aliases"
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
# Mailbox name
COMPREPLY=( $(compgen -W "$mboxes" $cur) );
elif [[ "$prev" == -a ]] || [[ "$prev" == -F ]] || \
[[ "$prev" == -H ]] || [[ "$prev" == -i ]]
then
# Files: attach (-a), alternate muttrc (-F), headers (-H), include
# (-i)
COMPREPLY=( $(compgen -W "$(echo *)" $cur) )
elif [[ "$prev" == -m ]]
then
# Mailbox type: mbox, MMDF, MH, Maildir
COMPREPLY=( $(compgen -W "mbox MMDF MH Maildir" $cur ) )
# elif [[ "$prev" == -b ]] || [[ "$prev" == -c ]]
# then
# # Addresses: Cc (-c) and Bcc (-b)
# addresses=$(awk '$NF~/>$/{gsub("[<>]","",$NF); print $NF}' $ALIASES)
# COMPREPLY=( $(compgen -W "$addresses" $cur) )
else
# Default: Mutt help (mutt -h)
COMPREPLY=( $(compgen -W "$($MUTT -h | awk '/^ *\-/{printf "%s ", $1}')" $cur)
)
fi
return 0;
}
complete -F _mutt -o default mutt