Zsh Autocompletion – Setting Up for New Executables in PATH

zsh

After copying a new executable to PATH, bash autocompletion for that command kicks in no problem, but zsh needs to be restarted.

How do I nudge zsh autocompletion to pick it up without restarting the shell?
Can it pick it up automatically?

Best Answer

How do I nudge zsh autocompletion to pick it up

Use rehash:

  • rehash re-computes the internal hash table of the contents of directories listed in the path environment variable to account for new commands added.

Persistent rehash

Typically, compinit will not automatically find new executables in the $PATH. For example, after you install a new package, the files in /usr/bin would not be immediately or automatically included in the completion. Thus, to have these new exectuables included, one would run:

$ rehash

This 'rehash' can be set to happen automatically. Simply include the following in your zshrc:

~/.zshrc
zstyle ':completion:*' rehash true

Source zsh - Persistent rehash

Related Question