From a4fadf1eaeac41a2a78f59c354425fdb09b2df8d Mon Sep 17 00:00:00 2001 From: Gregory Myers Date: Thu, 5 Nov 2026 11:04:35 +0000 Subject: [PATCH] [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 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 54945dfa..34a78764 100644 --- a/README.md +++ b/README.md @@ -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)"