From cc8e1a05f16569ab6e64496f947aed1454e1241b Mon Sep 17 00:00:00 2001 From: Brian Gray <638937+brianmgray@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:10:47 -0400 Subject: [PATCH] Add support for NVM_SILENT environment variable #91 --- README.md | 11 +++++++++++ zsh-nvm.plugin.zsh | 14 +++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 53a70c2..cc73569 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,17 @@ export NVM_AUTO_USE=true antigen bundle lukechilds/zsh-nvm ``` +### Silent switching + +If you use `Auto use` feature of this plugin with a theme that supports node version printing, you may want to disable some messages that nvm prints when it switches between versions. You can disable it by exporting the `NVM_SILENT` environment variable and setting it to `true`. + +For example, if you are using antigen, you would put the following in your `.zshrc`: + +```shell +export NVM_SILENT=true +antigen bundle lukechilds/zsh-nvm +``` + ## Installation ### Using [Antigen](https://github.com/zsh-users/antigen) diff --git a/zsh-nvm.plugin.zsh b/zsh-nvm.plugin.zsh index f4f56f3..f24aa46 100644 --- a/zsh-nvm.plugin.zsh +++ b/zsh-nvm.plugin.zsh @@ -176,11 +176,19 @@ _zsh_nvm_auto_use() { if [[ "$nvmrc_node_version" = "N/A" ]]; then nvm install && export NVM_AUTO_USE_ACTIVE=true elif [[ "$nvmrc_node_version" != "$node_version" ]]; then - nvm use && export NVM_AUTO_USE_ACTIVE=true + if [[ "$NVM_SILENT" == true ]]; then + nvm use --silent && export NVM_AUTO_USE_ACTIVE=true + else + nvm use && export NVM_AUTO_USE_ACTIVE=true + fi fi elif [[ "$node_version" != "$(nvm version default)" ]] && [[ "$NVM_AUTO_USE_ACTIVE" = true ]]; then - echo "Reverting to nvm default version" - nvm use default + if [[ "$NVM_SILENT" == true ]]; then + nvm use default --silent + else + echo "Reverting to nvm default version" + nvm use default + fi fi }