浏览代码

fix(nvm): prevent duplicates in lazy_cmd

Closes #11344
Carlo Sala 4 月之前
父节点
当前提交
8a8a04f43a
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      plugins/nvm/nvm.plugin.zsh

+ 7 - 2
plugins/nvm/nvm.plugin.zsh

@@ -24,9 +24,14 @@ if zstyle -t ':omz:plugins:nvm' lazy && \
   ! zstyle -t ':omz:plugins:nvm' autoload; then
   # Call nvm when first using nvm, node, npm, pnpm, yarn or other commands in lazy-cmd
   zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
+  nvm_lazy_cmd=(nvm node npm npx pnpm yarn $nvm_lazy_cmd) # default values
   eval "
-    function nvm node npm npx pnpm yarn $nvm_lazy_cmd {
-      unfunction nvm node npm npx pnpm yarn $nvm_lazy_cmd
+    function $nvm_lazy_cmd {
+      for func in $nvm_lazy_cmd; do
+        if (( \$+functions[\$func] )); then
+          unfunction \$func
+        fi
+      done
       # Load nvm if it exists in \$NVM_DIR
       [[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
       \"\$0\" \"\$@\"