9

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?

1 Answer 1

11

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
5
  • I see that I just accepted this answer. I think I should have also said: "awesome this is exactly what I need" -ed. thx ;-).
    – ttyS0
    Sep 29, 2019 at 21:03
  • That is very cool. What would be the accept-exact-dirs style for bash? Thanks Mar 27, 2022 at 19:50
  • @waterstone Bash's completion is a lot less powerful. It probably doesn't have anything similar. Mar 27, 2022 at 20:19
  • zsh path completion on the nfs was painfully slow that I couldn't even use it. After adding the accept-exact-dirs it fixed the problem. I had to strace the difference of what zsh and bash were doing and noticed that zsh was trying to stat directories not part of the path I was typing and getting access denied. Thanks!
    – postelrich
    Sep 20, 2022 at 14:57
  • Thanks; for me the completion of anything like cd ../ followed by double tab was absurdly, unusably slow. Killing this feature is a huge performance gain.
    – El Yobo
    May 17, 2023 at 11:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .