Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Just started using zsh with oh-my-zsh, and I noticed something odd when autocompleting with cd.

Suppose I have a folder:


When I used bash, I could type:

$ cd p<tab>

And nothing would happen because nothing in my_folder starts with p, but if I do the same thing in zsh, it autocompletes to the word proxy, which I'm assuming is some directory somewhere else in the file system?

I'm not sure if something is set up wrong, or if this is something about the way autocomplete works in zsh that I don't understand.


Output of CTRL+Xh:

tags in context :completion::complete:cd::
    local-directories named-directories      (_alternative _cd (eval)) 
    users named-directories directory-stack  (_tilde _alternative _cd (eval)) 
    users                                    (_users _tilde _alternative _cd (eval))
share|improve this question
never used zsh, but I know bash supports completing hostnames from /etc/hosts in addition to folders that exists. Is there a proxy in your hosts file? – penguin359 Jul 8 '11 at 5:36
Does $CDPATH include a directory that contains a subdirectory called proxy? If so, that's the desired behavior. – Gilles Jul 8 '11 at 6:17
Both good suggestions, but it doesn't look like it has anything to do with my hosts file and $CDPATH just returns .. – seth Jul 8 '11 at 13:36
Out of curiosity, was there a user named 'proxy' on your system? – Larold Sep 20 '11 at 18:36
@Larold Not that I see. – seth Sep 22 '11 at 13:46
up vote 5 down vote accepted

I'm not sure if you're still tracking this question, but I'd like to help. It's been awhile since I've dove into the guts of zsh's completion system, so this will be a good excuse.

For now, we'll use this answer as an ongoing tool for me to provide useful tidbits to help you (and I) troubleshoot the problem.

As you can tell, zsh's completion system is very powerful. Sometimes, it completes items that you don't want completed. For example, you almost always want to limit arguments to the 'cd' command to be directories. HOWEVER, in zsh, those could be filesystem directories, named directories, directories in various path variables, or even directories stored in standard shell variables. So, I think the first step is to determine the "context" of your completion.

Please cd into the my_folder directory above, and then type:

cd p<CTRL-X>h

CTRL-Xh is the default key combo to display the current context for completion. Please let me know what the output from this key combo is. For example, my output looked like this:

tags in context :completion::complete:cd::
    local-directories  (_alternative _cd (eval))

The key item to notice is 'local-directories'. What we DON'T see here is a commonly-occurring item 'path-directories', which refers to directories that can be found in $cdpath, and possibly other locations. (I can't remember offhand.)

If you see items other than 'local-directories', that will be a hint as to where this rogue 'proxy' entry might be coming from. For example, here are the types of items my zsh setup will try to complete if I attempt completion from the beginning of the command-line without typing anything:

commands builtins functions aliases suffix-aliases reserved-words jobs parameters  

You may indeed see one or more of those items with your CTRL-Xh output, or even items I don't list above. (Those are just examples)

Here is a way you might be able to help limit zsh to only providing local directories and $cdpath directories as completion options:

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

If you don't want some moderately-useful cd magic that zsh offers, drop the 'path-directories' from the end, and I believe you'll get the behavior you want. You'll want to put this into your .zshrc file to make it persistent across sessions. Let me know if this helps.

share|improve this answer
Thank you! This answers my question perfectly. Looks like I just had more going on for that context than I wanted. – seth Sep 14 '11 at 19:54
@seth Out of curiosity, were you able to find what type of item 'proxy' was, or where it was coming from? – Larold Sep 14 '11 at 19:57
Actually no. When I went to recreate this problem today, I got some interesting suggestions from autocomplete, but 'proxy' wasn't one of them. – seth Sep 14 '11 at 20:16
Interesting. It's always amazing how many different kinds of things zsh can complete on. It definitely takes some diligence customizing what gets completed where, but once you put some time into it, you can achieve some amazing results. – Larold Sep 14 '11 at 20:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.