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

Completion for cd



I am using zsh 5.3.1. For a long time I've had the following completion
configuration:

zstyle ':completion:*' matcher-list 'm:{[:lower:]}={[:upper:]}' '+l:|=*'
zstyle ':completion::*:::' completer _expand _complete _prefix _approximate
_ignored
cdpath=(. /opt)

The idea is of course that if something I write is the start of a
completion, I want it to be completed. If such match is _not_ found, I want
completion to the left (prefix completion?) to be attempted. It works well.
If I stand in a directory 'statistics' containing the directories
'stats-lib' and 'stats-web', I can write 'cd web<tab>' and have it
completed to 'stats-web'. That is what I want.

However, I have a slight problem with it. In my '/opt' directory, I have a
directory called 'webcert'. If I stand in the 'statistics' directory,
writing 'cd web<tab>' gives me 'webcert', since '/opt' is in the cdpath
array. This is as expected since I have configured matcher-list to prefer
what is a prefix to what is a suffix, so 'webcert' (in the cdpath) is
found, and therefore 'stats-web' (in the current directory) is never
offered.

I would like to keep the matcher-list configuration, but for the cmpletion
to prefer matches in the current directory over matches in cdpath. I
therefore added the following configuration:

zstyle ':completion:*:*:cd:*:*' completer _expand _complete
_complete:withpath _prefix _approximate _ignored
zstyle ':completion:*:complete:cd:*:*' tag-order local-directories -
zstyle ':completion:*:withpath:cd:*:*' tag-order path-directories

This works as intended: now 'stats-web' in the current directory is
preferred over 'webcert' in cdpath, so typing 'cd web<tab>' completes to
'stats-web'. If I want to go to 'webcert', I can type 'cd webc<tab>' and it
will complete to 'webcert'.

However, now I find a surprising side-effect of this change. I have also
this configuration:

zstyle ':completion:*:*:cd:*:*' ignore-parents parent pwd

But this is broken by my change! If I go to directory 'zsh' in
'/usr/local/Cellar', and then type 'cd ../z<tab>', I am offered 'zsh'
together with 'zsh-completion', whereas before the change, I would only be
offered 'zsh-completion', since I have configured cd to ignore the current
directory.

I can't figure out why my configuration change has caused the
'ignore-parents' style to stop working.


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