I have a directory with a single subdirectory named src. I'd expect when typing in cd s and hitting TAB for the directory to be completed. Instead, zsh tries to complete all users on the system starting with a s:

Completing local directory
Completing user
saeumair  sbrg      scan-nix  schlosse  sdwoods   shutdown   
sis-user  smmsp     snitch    srabhina  sshd      sterpeni  sushid    sync 

I'm guessing the guilty line in my .zshrc is:

zstyle ':completion:*:directory-stack' list-colors '=(#b) \
        #([0-9]#)*( *)==95=38;5;12'

Which I'm using to be able to complete cd history. Any idea how I can keep this functionality while not completing for users?

2 Answers 2


The cdablevars option is responsible for making named directories and hence users a valid argument to cd. If you don't use that, use unsetopt cdablevars.

To change what is completed for cd, you can use the tag-order style. For example, to try only local-directories first, it would be:

    zstyle ':completion:*:cd:*' tag-order local-directories

A handy key shortcut for seeing the applicable tags in a certain context is to press Ctrl-X h instead of tab.


Users are valid parameters for the cd command, and thus are offered as completion, because you have the option cdable_vars turned on. With this option, cd foo can be used instead of cd ~foo, which allows foo to be anything that can be tilde-expanded, including a user name or a directory name set by hash -d (but not shell variables, despite the name of the option).

There is no option in the completion code to allow named directories but not attempt to complete them. You could work around this with a wrapper to the completion function for cd.

unset -f _cd
autoload -U _cd
_cd () {
  setopt local_options no_cdable_vars
  _cd_orig $@[@]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .