Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Ignore commands if autocomplete to directory is possible



On Apr 24, 10:41pm, Prateek Agarwal wrote:
}
} I am using setopt auto_cd. But when autocompleting for directories, i want
} that first preference is to be given to directories than to commands. Which
} means, if directory is present that matches the substring then zsh should
} not search for commands.

Hmm.  Ordinarily you'd do this with the tag-order style like

    # Note this does not actually work
    zstyle ':completion:*:-command-::' tag-order \*-directories

(the "everything else" is implied if no directories match).  However,
this doesn't work for autocd because the _autocd function explicitly
calls _command_names before testing the autocd option and then calling
_cd.  So there's no way to exclude command names with a style in this
context, except by *always* exluding them (which you don't want).

You have two options.

You can replace the _autocd function with this:

    _autocd() { [[ -o autocd ]] && _cd || _command_names }

Or you can use a group-order style:

    zstyle ':completion:*:-command-::' group-order \*-directories

which will cause all the directory names to appear first in the menu,
even though any commands that match will also appear.



Messages sorted by: Reverse Date, Date, Thread, Author