ZSH + Prezto: CD Tab Completion Issue

1k views Asked by At

I've been thinking about switching over to zsh and prezto for some time now, but there are some nuisances that I'd like to solve first.

Biggest of these is the fact that it seems like the tab completion for 'cd' is messed up somehow. For instance, I've a directory called "git" in my home directory for my git projects and I frequently want to move to it from the home directory, that is, I write this:

~ >>> cd g[TAB]
~ >>> cd git

Since "git" is the only folder starting with a "g" I obviously expect that to be the result of the tab completion. However, with ZSH and prezto, it instead completes it like this:

~ >>> cd g[TAB]
~ >>> cd gnats

Using tab again will also try to complete a subfolder to "gnats", neither of which exists!

So far I've at figured out that this is most likely caused by prezto, since disabling it reverts back to the expected behavior.

Any ideas what configuration I have to add to fix this?

1

There are 1 answers

0
Adaephon On BEST ANSWER

The most likely culprit is the shell option CDABLE_VARS. You can check if it is set with setopt | grep cdablevars. As it is not a default setting you can either find where it is set within prezto or explicitly unset it with setopt nocdablevars after prezto is sourced.

Explanation:

If CDABLE_VARS is set, zsh handles arguments to cd that are not directories and do not begin with / as if they begin with ~. This extends to the autocompletion for cd.

If a directory name starts with ~ (as is implied by CDABLE_VARS), zsh checks if the element up to the first / can be subsituted in a few different ways. In your case, ~gnats is interpreted as static named directory, which may defined by the following means:

  1. automatically for home directories: ~someone is the home directory of the user someone.
  2. by setting a shell parameter to a string value which begins with /:

    % SOMEWHERE=/some/directory
    % print ~SOMEWHERE
    /some/directory
    
  3. by using hash -d: hash -d SOMEWHERE=/some/directory

I would guess that in this case it is the home directory of the user gnats. Which - as far as I can tell - seems to be created by default on at least Debian and Ubuntu.