Disabling ZSH user completion

ZSH has proven to be one of the most powerful shells i've used so far. It has really surprised me dozens of times and I started to love it much more than bash or anything else.

Unfortunately, ZSH can also suffer from the fact that it's so powerful. Among the things that made me almost cry was the user completion, enabled by default, that made the whole console freeze for long time before it finally resumed, giving me a list of hundreds LDAP users when all I wanted is a completion of local directory.

After longer search I finally mastered the query to get the right solution to the problem:

unsetopt cdablevars

This short line turns off auto-completion based on user names and variables. Once in place you will no longer be able to type:

cd user_name
cd var_name

instead, you're back to standard

cd ~user_name
cd $var_name

but, the upside is, the directory completion (when you press TAB key) is again working smoothly, even when you're completing commands (git etc).

Among available alternatives you can find a solution that would disable completion for a particular command, such as:

zstyle ':completion:*:complete:(cd|pushd):*' tag-order \
    'local-directories path-directories directory-stack' '*'
which will complete cd and pushd commands with directories only (so, no variables and no users for you). You can try to tweak this completion pattern to actually give you some of these mechanisms back to these commands.

No comments:

Post a Comment