From 46c70406dd0b26bbd61210873ad6c86d9e8ee5da Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 7 Jun 2023 18:43:47 +0200 Subject: feat(nvm): add `npx` to lazy trigger list Closes #11740 --- plugins/nvm/README.md | 2 +- plugins/nvm/nvm.plugin.zsh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/nvm') diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index d3fd980be..6830c14d0 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -26,7 +26,7 @@ These settings should go in your zshrc file, before Oh My Zsh is sourced: #### Lazy startup This option will help you to defer nvm's load until you use it to speed-up your zsh startup. This will source -nvm script only when using it, and will create a function for `node`, `npm`, `pnpm`, `yarn`, and the +nvm script only when using it, and will create a function for `node`, `npm`, `npx`, `pnpm`, `yarn`, and the command(s) specified by `lazy-cmd` option, so when you call either of them, nvm will be loaded and run with default version. To enable it, you can add this snippet to your zshrc, before Oh My Zsh is sourced: diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 20697d67d..31d275415 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -43,8 +43,8 @@ if zstyle -t ':omz:plugins:nvm' lazy; 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 " - function nvm node npm pnpm yarn $nvm_lazy_cmd { - unfunction nvm node npm pnpm yarn $nvm_lazy_cmd + function nvm node npm npx pnpm yarn $nvm_lazy_cmd { + unfunction nvm node npm npx pnpm yarn $nvm_lazy_cmd # Load nvm if it exists in \$NVM_DIR [[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\" \"\$0\" \"\$@\" -- cgit v1.2.3-70-g09d2 From 4ba17232dae591f67b8e474fb013d2cb6555696e Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 20 Jun 2023 08:54:35 +0200 Subject: feat(nvm)!: remove soft-deprecated code BREAKING CHANGE: $NVM_LAZY, $NVM_LAZY_CMD, AND $NVM_AUTOLOAD cannot be used anymore to tweak nvm plugin. Use zstyle-based configurations instead. --- plugins/nvm/nvm.plugin.zsh | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'plugins/nvm') diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 31d275415..943678f7a 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -16,29 +16,6 @@ fi # Note: nvm is a function so we need to use `which` which nvm &>/dev/null && return -# TODO: 2022-11-11: Remove soft-deprecate options -if (( ${+NVM_LAZY} + ${+NVM_LAZY_CMD} + ${+NVM_AUTOLOAD} )); then - # Get list of NVM_* variable settings defined - local -a used_vars - used_vars=(${(o)parameters[(I)NVM_(AUTOLOAD|LAZY|LAZY_CMD)]}) - # Nicely print the list in the style `var1, var2 and var3` - echo "${fg[yellow]}[nvm plugin] Variable-style settings are deprecated. Instead of ${(j:, :)used_vars[1,-2]}${used_vars[-2]+ and }${used_vars[-1]}, use:\n" - if (( $+NVM_AUTOLOAD )); then - echo " zstyle ':omz:plugins:nvm' autoload yes" - zstyle ':omz:plugins:nvm' autoload yes - fi - if (( $+NVM_LAZY )); then - echo " zstyle ':omz:plugins:nvm' lazy yes" - zstyle ':omz:plugins:nvm' lazy yes - fi - if (( $+NVM_LAZY_CMD )); then - echo " zstyle ':omz:plugins:nvm' lazy-cmd $NVM_LAZY_CMD" - zstyle ':omz:plugins:nvm' lazy-cmd $NVM_LAZY_CMD - fi - echo "$reset_color" - unset used_vars NVM_AUTOLOAD NVM_LAZY NVM_LAZY_CMD -fi - if zstyle -t ':omz:plugins:nvm' lazy; 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 -- cgit v1.2.3-70-g09d2 From b5be2d39e2d2a598f7bba26d0bae2cce8c7d3d64 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 20 Jun 2023 09:36:11 +0200 Subject: fix(nvm): disable lazy-loading if autoload is set Closes #11748 --- plugins/nvm/README.md | 3 +++ plugins/nvm/nvm.plugin.zsh | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'plugins/nvm') 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 -- cgit v1.2.3-70-g09d2 From 8bdb5c959c9a5c74d3b59c05a3a0bca5e602c3cd Mon Sep 17 00:00:00 2001 From: Jarrett Lusso Date: Sat, 15 Jul 2023 16:10:48 -0400 Subject: docs(nvm): clarify autoload setup (#11797) --- plugins/nvm/README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'plugins/nvm') diff --git a/plugins/nvm/README.md b/plugins/nvm/README.md index eee3bf717..b5ef221d3 100644 --- a/plugins/nvm/README.md +++ b/plugins/nvm/README.md @@ -52,12 +52,7 @@ version to load. This can be done, similar as previous options, adding: ```zsh zstyle ':omz:plugins:nvm' autoload yes -``` - -To remove the output generated by NVM when autoloading, you can set the following option: - -```zsh -zstyle ':omz:plugins:nvm' silent-autoload yes +zstyle ':omz:plugins:nvm' silent-autoload yes # optionally remove the output generated by NVM when autoloading ``` Note: _this will not remove regular `nvm` output_ -- cgit v1.2.3-70-g09d2 From 7cf00a0b5cf0f25c16fc7902f78dff480e03fe3d Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 19 Jul 2023 14:46:35 +0200 Subject: fix(nvm): remove nvm not found verbose message --- plugins/nvm/nvm.plugin.zsh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'plugins/nvm') diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 484ef2964..1badbeab5 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -16,13 +16,7 @@ fi # Note: nvm is a function so we need to use `which` which nvm &>/dev/null && return -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" +if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then return fi -- cgit v1.2.3-70-g09d2