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

Re: Question about _directories

Mark Daniel Reidel <mark@xxxxxxxxxxx> wrote:
>On Fri, 18 Apr 2008 11:11:08 +0100
>Peter Stephenson <pws@xxxxxxx> wrote:
>> On Wed, 16 Apr 2008 18:56:09 +0200
>> Mark Daniel Reidel <mark@xxxxxxxxxxx> wrote:
>> > I'm currently writing a file for tab-completion of a script and I have
>> > a problem: on a certain parameter, it has to accept all
>> > sub-sub-directories of /usr/ports. So /usr/ports/a/b/ is good,
>> > but /usr/ports/a/b/c should not be found. Of course /usr/ports/a<tab>
>> > should list everything starting with a as well, but how can I limit
>> > that it should only work 2 directories deep with _directories?
>> I think a fairly simple wrapper will work.  Try something like:
>> if [[ $PREFIX = /usr/ports/*/*/* ]]; then
>>   return 1
>> else
>>   _directories
>> fi
> Yes, that's almost exactly what I want, works great!
> The only thing is that completion "stops" at, for
> example, "/usr/ports/a/b/" instead of feeling like a good match and
> accepting it like "/usr/ports/a/b " and moving the cursor a bit right.
> Is there any way to achieve this or would that be about several hundred
> lines of code, totally not worth the effort? :o)

(Your Face: header triggered our mail quarantine, so I'm having to reply a
different way.)

Does this work?  I only had a brief play.  The trick is that when you get
into /usr/ports/*/ you give it a specific pattern to match in a specific

local -a match mbegin mend

if [[ $PREFIX = (#b)(/usr/ports/[^/]#/)* ]]; then
  compset -p ${#match[1]}
  _path_files -W $match[1] -g '*/'
  return 1

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070

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