70a0577712bc8f78e14173c8032df3701ea2887f

Author
Guo, Quan <1118270+guoquan@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(nvm): introduce customizable list of command that triggers lazy loading (#9946)

* Add customizable list of command that triggers lazy loading

* Add $NVM_LAZY_CMD

* Add instruction to `NVM_LAZY_CMD` in README.md

Diff

 1diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md
 2index 7006130851167a2c602f242537b3d8641235179a..0c2bbf9f04a4a8847205206b96fe755cf5057feb 100644
 3--- a/plugins/nvm/README.md
 4+++ b/plugins/nvm/README.md
 5@@ -21,7 +21,11 @@ These settings should go in your zshrc file, before Oh My Zsh is sourced:
 6 
 7 - **`NVM_LAZY`**: if you want the plugin to defer the load of nvm to speed-up the start of your zsh session,
 8   set `NVM_LAZY` to `1`. This will use the `--no-use` parameter when loading nvm, and will create a function
 9-  for `node`, `npm` and `yarn`, so when you call either of these three, nvm will load with `nvm use default`.
10+  for `node`, `npm`, `yarn`, and the command(s) specified by `NVM_LAZY_CMD`, so when you call either of them,
11+  nvm will load with `nvm use default`.
12+
13+- **`NVM_LAZY_CMD`**: if you want additional command(s) to trigger lazy loading of nvm, set `NVM_LAZY_CMD` to
14+  the command or an array of the commands.
15 
16 - **`NVM_AUTOLOAD`**: if `NVM_AUTOLOAD` is set to `1`, the plugin will automatically load a node version when
17   if finds a [`.nvmrc` file](https://github.com/nvm-sh/nvm#nvmrc) in the current working directory indicating
18diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh
19index 1e9b26e7a9232837655c857895bedcf0d0c54555..3ef8cc1d8e62549ecc860ec28b1876953e19df77 100644
20--- a/plugins/nvm/nvm.plugin.zsh
21+++ b/plugins/nvm/nvm.plugin.zsh
22@@ -28,8 +28,8 @@ fi
23 
24 # Call nvm when first using node, npm or yarn
25 if (( $+NVM_LAZY )); then
26-  function node npm yarn {
27-    unfunction node npm yarn
28+  function node npm yarn $NVM_LAZY_CMD {
29+    unfunction node npm yarn $NVM_LAZY_CMD
30     nvm use default
31     command "$0" "$@"
32   }