4

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

Suppose I have a folder:

my_folder/
    subfolder/
    another_subfolder/
    file.txt

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.

EDIT:

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))
seth
  • 145
  • 5

1 Answers1

6

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.

Larold
  • 812
  • 4
  • 13
  • 21
  • 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