From 1514145a09140425b914e9cd98fc1d638a8c4003 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 19 Sep 2024 11:44:51 +0200 Subject: [PATCH] feat(nvm): add `_omz_nvm_load` function --- plugins/nvm/README.md | 2 ++ plugins/nvm/nvm.plugin.zsh | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index fe91cc3b2..1245f66db 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -42,6 +42,8 @@ as you want: zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ... ``` +There will be a function `_omz_nvm_load` available to load `nvm` without executing any other trigger command. + #### `.nvmrc` autoload Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_ diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index a00c2e117..682bddc47 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -20,7 +20,7 @@ if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then return fi -function _omz_load_nvm_completion { +function _omz_nvm_setup_completion { local _nvm_completion # Load nvm bash completion for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do @@ -33,12 +33,12 @@ function _omz_load_nvm_completion { break fi done - unfunction _omz_load_nvm_completion + unfunction _omz_nvm_setup_completion } -function _omz_setup_autoload { +function _omz_nvm_setup_autoload { if ! zstyle -t ':omz:plugins:nvm' autoload; then - unfunction _omz_setup_autoload + unfunction _omz_nvm_setup_autoload return fi @@ -68,13 +68,13 @@ function _omz_setup_autoload { add-zsh-hook chpwd load-nvmrc load-nvmrc - unfunction _omz_setup_autoload + unfunction _omz_nvm_setup_autoload } if zstyle -t ':omz:plugins:nvm' lazy; then # Call nvm when first using nvm, node, npm, pnpm, yarn, corepack or other commands in lazy-cmd zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd - nvm_lazy_cmd=(nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values + nvm_lazy_cmd=(_omz_nvm_load nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values eval " function $nvm_lazy_cmd { for func in $nvm_lazy_cmd; do @@ -84,14 +84,16 @@ if zstyle -t ':omz:plugins:nvm' lazy; then done # Load nvm if it exists in \$NVM_DIR [[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\" - _omz_load_nvm_completion - _omz_setup_autoload - \"\$0\" \"\$@\" + _omz_nvm_setup_completion + _omz_nvm_setup_autoload + if [[ \"\$0\" != _omz_nvm_load ]]; then + \"\$0\" \"\$@\" + fi } " unset nvm_lazy_cmd else source "$NVM_DIR/nvm.sh" - _omz_load_nvm_completion - _omz_setup_autoload + _omz_nvm_setup_completion + _omz_nvm_setup_autoload fi