diff options
author | Carlo Sala <carlosalag@protonmail.com> | 2023-06-20 09:36:11 +0200 |
---|---|---|
committer | Carlo Sala <carlosalag@protonmail.com> | 2023-06-20 09:36:11 +0200 |
commit | b5be2d39e2d2a598f7bba26d0bae2cce8c7d3d64 (patch) | |
tree | 4b14654103c67076b78c18c681bceb7af3039cb0 /plugins | |
parent | 4ba17232dae591f67b8e474fb013d2cb6555696e (diff) | |
download | zsh-b5be2d39e2d2a598f7bba26d0bae2cce8c7d3d64.tar.gz zsh-b5be2d39e2d2a598f7bba26d0bae2cce8c7d3d64.tar.bz2 zsh-b5be2d39e2d2a598f7bba26d0bae2cce8c7d3d64.zip |
fix(nvm): disable lazy-loading if autoload is set
Closes #11748
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/nvm/README.md | 3 | ||||
-rw-r--r-- | plugins/nvm/nvm.plugin.zsh | 18 |
2 files changed, 16 insertions, 5 deletions
diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index 6830c14d0..eee3bf717 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -43,6 +43,9 @@ zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ... #### `.nvmrc` autoload +Note: _this option cannot be used at the same time as `lazy`. `autoload` will override it and load `nvm` at +startup._ + If set, the plugin will automatically load a node version when if finds a [`.nvmrc` file](https://github.com/nvm-sh/nvm#nvmrc) in the current working directory indicating which node version to load. This can be done, similar as previous options, adding: diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 943678f7a..484ef2964 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -16,7 +16,18 @@ fi # Note: nvm is a function so we need to use `which` which nvm &>/dev/null && return -if zstyle -t ':omz:plugins:nvm' lazy; then +if [[ -z "$NVM_DIR" ]]; then + echo "[oh-my-zsh] nvm installation cannot be found" + echo "[oh-my-zsh] set NVM_DIR to your installation" + return +fi +if [[ ! -f "$NVM_DIR/nvm.sh" ]]; then + echo "[oh-my-zsh] nvm.sh does not exist in $NVM_DIR" + return +fi + +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 eval " @@ -28,11 +39,8 @@ if zstyle -t ':omz:plugins:nvm' lazy; then } " unset nvm_lazy_cmd -elif [[ -f "$NVM_DIR/nvm.sh" ]]; then - # Load nvm if it exists in $NVM_DIR - source "$NVM_DIR/nvm.sh" else - return + source "$NVM_DIR/nvm.sh" fi # Autoload nvm when finding a .nvmrc file in the current directory |