Zsh – How to Stop Zsh from Completing Parent Directories

autocompletefilenameszsh

I am using zsh with grml's zshrc as a base. As part of my work I access network path regulary (e.g NFS. AFS.)

If I write /a/long/network/path/on/the/other/side/of/the/world press TAB twice it is painfully slow as zsh start searching under /a/ then /a/long /a/long/network etc…

At the same time running ls /a/long/network/path/on/the/other/side/of/the/world returns in a sec. So I would like to tell zsh to stop second guessing me.
(If I write /usr/src/linuxx/ and then press tab it figures out that i wanted /usr/src/linux/ and this is cool however because the network it does me more harm than good). I would like to only autocomplete "at the end" after the last slash.

Sometimes I am using a workaround cd into the directory then use autocompletion. Surely there must be a better way.

How can I achieve this?

Best Answer

This kind of behavior is configured through styles (except for a few fundamentals that have options). You'll want to turn off path-completion.

By default, filename completion examines all components of a path to see if there are completions of that component. For example, /u/b/z can be completed to /usr/bin/zsh. Explicitly setting this style to false inhibits this behaviour for path components up to the / before the cursor

zstyle ':completion:*' path-completion false

You may want to turn on accept-exact-dirs instead. With path-completion left on and accept-exact-dirs turned on, zsh will only attempt completion for path components other than the last one if the path doesn't exist.

zstyle ':completion:*' accept-exact-dirs true