Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: _mutt, _mailboxes



On Sep 15,  5:30pm, Clint Adams wrote:
} Subject: PATCH: _mutt, _mailboxes
}
} This is my stab at completion for mutt.  I imagine that the
} _mailboxes function would be useful for completing the -f arguments
} of elm and pine, after some tweaking.
} 
} + test -f "$compconfig[muttrc_path]" && muttrc=$compconfig[muttrc_path]
} + test -f "$compconfig[maildirectory]" && maildirectory=$compconfig[maildirectory]

The following are updates to _mailboxes to make it somewhat more generic.

Other completers don't use compconfig for anything as application-specific
as "muttrc_path", so instead I've simply made it recognize the existing
settings of $muttrc and $maildirectory if there are any.  I've added the
paramter $pinedirectory to that set, as Pine by default uses ~/mail where
mutt, mush, zmail, and plain ol' mail all use ~/Mail; I could have stabbed
at ~/nsmail (netscape communicator) and various other programs' directory
names; but I don't really even like the idea of _mailboxes handling the
maildir and MH formats, so I didn't.

Nevertheless, I did improve (I hope) the handling of MH format as well, to
do a better job of recognizing nested mailbox hierarchy.

I don't use mutt, so I don't know what ( \! \< \> ) are; do they really
represent mailbox names?  If not, they should be in _mutt and not here.
As I didn't know, I simply relegated them to the same collection of names
as those grepped from the .muttrc file, and didn't include them at all if
there is no such collection.

One thing I didn't do yet is handle a leading "+" in the word that is
being completed and treat it as referring to the maildirectory.

Index: Completion/User/_mailboxes
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-3.1/Completion/User/_mailboxes,v
retrieving revision 1.1
diff -u -r1.1 _mailboxes
--- _mailboxes	1999/09/18 17:26:25	1.1
+++ _mailboxes	1999/09/18 23:22:02
@@ -1,30 +1,41 @@
 #autoload
 
-# This is needlessly mutt-biased and should be fixed.
+emulate -L zsh
+setopt nullglob
 
-local expl muttboxes mboxes dirboxes MHboxes maildirboxes muttrc="~/.muttrc" maildirectory="~/Mail"
+# This is still needlessly mutt-biased and should be fixed.
 
-test -f "$compconfig[muttrc_path]" && muttrc=$compconfig[muttrc_path]
-test -f "$compconfig[maildirectory]" && maildirectory=$compconfig[maildirectory]
+local -U muttboxes mboxes dirboxes MHboxes maildirboxes
+local i j expl muttrc="${muttrc:-~/.muttrc}"
+local pinedirectory="${pinedirectory:-~/mail}"
+local maildirectory="${maildirectory:-~/Mail}"
 
 if (( ! $+_mailbox_cache )) then
 
-test ${muttrc} || test -f ${~muttrc} && muttboxes=( ${(@)$(grep mailboxes ${~muttrc})[2,-1]} )
+[[ -f "${~muttrc}" ]] && muttboxes=( ${$(grep mailboxes ${~muttrc})[2,-1]} )
 
-mboxes=(${~maildirectory}/*(^/))
-dirboxes=(${~maildirectory}/*(/))
+mboxes=( ${~maildirectory}/*(^/) ${~pinedirectory}/**/*(.) )
+dirboxes=( ${~maildirectory}/*(/) )
 
-for i in $dirboxes
+while (( $#dirboxes ))
 do 
-if test -d "${i}/cur"
-then
-maildirboxes=($maildirboxes $i)
-else
-MHboxes=($MHboxes $i)
-fi
+    i=$dirboxes[1]
+    shift dirboxes
+    if [[ -d "$i/cur" ]]
+    then
+	maildirboxes=( $maildirboxes $i )
+    elif j=( $i/<1-> ) && [[ -n "$j" ]]
+    then
+	MHboxes=( $MHboxes $i )
+    else
+	mboxes=( $mboxes $i/*(.) )
+	dirboxes=( $dirboxes $i/*(/) )
+    fi
 done
 
-_mailbox_cache=(\! \< \> $muttboxes $mboxes $maildirboxes $MHboxes)
+[[ -n "$muttboxes" ]] &&
+    _mailbox_cache=(\! \< \> $muttboxes)
+_mailbox_cache=($_mailbox_cache $mboxes $maildirboxes $MHboxes)
 
 fi
 
 

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author