3

I like zsh's autocorrect for commands. It has an annoying feature, however: sometimes I try to run a command, notice it doesn't exist, install it, then try to run it again, and zsh still wants to make the same correction. Zsh does this because keeps a hash of command paths, and it doesn't go beyond the hash when doing autocorrection. If I say n to the correction after installing the command, the command does run, but I have to say n again each time I want to run the command, or update the command hash in each running instance by calling the hash builtin.

I do want zsh to keep a hash of command paths, and I want to keep autocorrection (i.e. I type a command name and press Enter as usual, and zsh suggests a correction if the command does not exist). However, I want “the command does not exist” to mean that the command is not on $path at this point in time, not that the command is does not exist.

Steps to reproduce:

$ mkdir /tmp/test
$ cp /bin/true /tmp/test/wibble
$ PATH=/tmp/test:/bin zsh -f -o correct
darkstar% wobble
zsh: correct 'wobble' to 'wibble' [nyae]? a
darkstar% cp /tmp/test/{wibble,wobble}
darkstar% wobble
zsh: correct 'wobble' to 'wibble' [nyae]? n

Desired behavior: when wobble exists, don't prompt to correct it. How can I do this?

  • I don't experience this on my system. automatically detects wobble without action. zsh 5.4.1 on fedora 27. All my *hash* options are set to "off". – Patrick May 20 '18 at 6:54
  • @Patrick I have the default settings for all hash options, meaning that hash_list_all, hash_cmds and hash_dirs are on. – Gilles May 20 '18 at 10:55
  • @Gilles : I understand that it should work in your case, but just for the safe side: Do you see the same effect, if you are doing an explicit rehash before trying the autocompletion again? – user1934428 May 21 '18 at 6:28
0

As mentioned by @user1934428, you can recreate the hash table explicitly by running rehash. To avoid doing it manually put this in your zshrc:

zstyle ":completion:*:commands" rehash 1

You can find out more about zstyle from zshmodule man page, and the styles themselves are documented in zshcompsys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.