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

Re: Standard 'filtering' mechanism?



On Sun, 14 Feb 2010, Peter Stephenson wrote:

> "Benjamin R. Haskell" wrote:
> > I'm still getting acquainted with the intricacies of Zsh completion 
> > and pattern matching.  One thing I've wanted to do for a while is 
> > prevent 'vim' completion from matching the various 'junk' files that 
> > are associated with various phases of TeX compilation.
> 
> If I've worked out correctly what you're trying to do (exclude files 
> which have the same basename as a .tex file)

Roughly, but not quite 'basename' exactly.  From my example, 
'document.tex' also produces the intermediate file: document-mpgraph.mp


> , how about something like this...
> 
> 
> vim-files() {
>   local dir
>   if [[ $PREFIX = */* ]]; then
>     if [[ $PREFIX[-1] = / ]]; then
>       dir=$PREFIX[1,-2]
>     else
>       dir=${PREFIX:h}
>     fi
>   else
>     dir=.
>   fi
>   local -a texfiles nontexfiles
>   local -aU suffixes
>   texfiles=($dir/*.tex(N))
>   if (( $#texfiles )); then
>     nontexfiles=(${texfiles:r}.*)
>     suffixes=(${${nontexfiles:e}:#tex})
>     reply=("^*.(${(j.|.)suffixes})")
>   fi
> }
> zstyle -e ':completion:*:*:vim:*' file-patterns vim-files

[example fixed for 'non' vs. 'no' that was just mentioned in a followup 
before I could send]

That, modulo the not-quite-basename problem will probably work.  But, it 
kind of gets to the heart of what I wanted to avoid (namely: doing the 
globbing manually).  It'd be much nicer to have _path_files handle the 
various PREFIX things your function does there, and then filter as a 
post-processing step.  I guess there's no zstyle way to 'hook' into that 
stage of completion?

-- 
Thanks,
Ben



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