[readme] zsh load-nvmrc: skip during tab completion

When completing a path containing `../` for `cd`, `pushd`, or `chdir`,
zsh's `_cd` runs `$(cd ${PREFIX%/*} ...)`,
which fires the `chpwd` hook in a subshell,
so `load-nvmrc` ran on each such completion, slowly in large directories.

`compstate` is set only inside completion widgets.
Checking `ZSH_SUBSHELL` instead would also skip deliberate subshells, like `( cd proj && npm test )`,
and checking it along with `WIDGET` would skip any widget's subshell, not just completion's.

Fixes #3606
This commit is contained in:
Gregory Myers authored and Jordan Harband committed 2026-11-05 11:04:35 +00:00
1 parent ecf142d1f0
commit a4fadf1eae
1 file changed
+2
+2
View File
@@ -862,6 +862,8 @@ Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you e
autoload -U add-zsh-hook
load-nvmrc() {
# skip during tab completion, which can run `cd` in a subshell
(( $+compstate )) && return
local nvmrc_path
nvmrc_path="$(nvm_find_nvmrc)"