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

Re: cd completion and CDABLE_VARS



Vincent Lefevre wrote:
> When I use completion with the cd command, zsh tries to complete
> to both directories and named directories, probably because I have
> CDABLE_VARS set. I would like cd to complete to directories by
> default, and if it is not possible (and only in this case), then
> the completion to named directories is performed. How can I do
> that?

This is an interesting question and I'm glad you asked (assuming
Oliver hasn't beaten me to it)...

There's a general procedure for things like this, whenever you have
recognisably different completions at a particular point.  Obviously,
that means `recognisable by the completion system', so it requires
someone to have thought about this in the implemenation of the function.
However, that happens to be the case here.

Go to the point where you want completion to be performed and type ^xh.
You should get something like:

tags in context :completion::complete:cd::
    local-directories path-directories named-directories  (_alternative _cd) 
    users named-directories directory-stack               (_tilde _alternative _cd) 
    users                                                 (_users _tilde _alternative _cd)

(I actually typed `cd z^xh' but it shouldn't matter much.)

Those names on the left of the list are what you want.  You now need to
tell the completion system what order you want it to show the tags:

zstyle ':completion:*:complete:cd:*' tag-order \
  'local-directories path-directories directory-stack' '*'

You may decide a different order, but the point is that
`named-directories' are not in the first set.  Note that I have tied
this to the cd command; you could used `(cd|pushd)', for example.

Now you should find you only get shown real directories and directory
stack entries, unless there aren't any.

One extra tip is that there is a widget _next_tags which you can use to
switch to the next set of tags even if the first set isn't empty.  It
switches round in a circle.  I use:

bindkey "^X^N" _next_tags

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



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