Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Adding array content to cd completion
- X-seq: zsh-users 10988
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Adding array content to cd completion
- Date: Wed, 15 Nov 2006 11:08:40 +0000
- In-reply-to: <20061115050938.GC7601@princo>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Cambridge Silicon Radio
- References: <20061115050938.GC7601@princo>
Jean-Rene David <jrdavid@xxxxxxxx> wrote:
> I have an array of directories I frequently visit.
> I would like the completion of "cd" to include
> those directories, as a separate group.
It depends how much work you want to do.
If you don't mind them appearing as named directories you can do:
mydirs=(mydir1 mydir1)
zstyle -e ':completion::complete:cd:*:named-directories' fake '$mydirs'
If you really want a separate group it's harder. The whole completion
system is written so that only a fixed set of tags are available for each
completion.
It's possible to use the tag-order to split a group into two, as described
in the manual. You can use this with, say, the named-directories tag to
have a normal completion and your own context. In your own context you
have to add your own matches using the fake style and then (the hairiest
part of the exercise) remove the normal matches with ignored-patterns.
Luckily in this case the matches to be ignored are parameter names
available from the associatiave array $nameddirs:
zstyle ':completion::complete:cd:*' tag-order \
'named-directories:-mine:extra\ directories
named-directories:-normal:named\ directories *'
mydirs=(mydir1 mydir2)
zstyle -e ':completion::complete:cd:*:named-directories-mine' fake \
'reply=($mydirs)'
zstyle -e ':completion::complete:cd:*:named-directories-mine' \
ignored-patterns 'reply=("(${(qkj.|.)nameddirs})")'
This seems to work. It's not clear it's easier than redefining _cd.
Arguably there should be an easier way of saying only use the fake matches.
I think that's quite difficult since all the normal matches have been added
and are in the shell's internal structures by the time that style is
processed.
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
Messages sorted by:
Reverse Date,
Date,
Thread,
Author