My CDPATH in zsh looks like this:
export CDPATH='.:..:../..'
Unfortunately, this means that when I try to autocomplete after typing 'cd ', there're way too many irrelevant autocomplete options, depending on where I am. For example, if I'm in my home directory, typing cd tries to autocomplete every user on the system because CDPATH has ".."
Is there a way to keep my CDPATH as shown above, but have the autocomplete for cd, pushd, etc. ignore the CDPATH value, and autocomplete only based on the current directory?
Answer
path-directories
One way is to add the following completion settings in your .zshrc
to remove path-directories
from the suggestion sources.
zstyle ':completion:*:complete:(cd|pushd):*' tag-order \
'local-directories named-directories'
group names
Alternatively or additionally, the following settings should display a heading for all respective groups of completion suggestions so you can see which directories are local directories and which are suggestions from your cdpath
.
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format %d
You can apply standard prompt formats to these descriptions to make them stand out:
zstyle ':completion:*:descriptions' format %B%d%b # bold
# zstyle ':completion:*:descriptions' format %S%d%s # invert/standout
# zstyle ':completion:*:descriptions' format %U%d%u # underline
# zstyle ':completion:*:descriptions' format %F{green}%d%f # green foreground
# zstyle ':completion:*:descriptions' format %K{blue}%d%k # blue background
# etc.
That helps make sense of the different sources quite a bit in my experience.
Note 1: zsh
has two representations for array variables like PATH
and CDPATH
, of which the lower case variant is an actual array. This means you can:
cdpath=(path/to/dir /path/to/another/dir)
Or, to get your desired result:
cdpath=(.. ../..)
I personally find it a bit more readable than the colon-separated pseudo array.
Note 2: Exporting CDPATH
isn't necessary unless you have several programs that want it set.
Comments
Post a Comment