From 49fe92d05b223a35741b10bd626a7f630e06171e Mon Sep 17 00:00:00 2001 From: Jeffery Bennett Date: Tue, 20 Jun 2017 23:32:58 -0500 Subject: [PATCH] Adding watch for .nvmrc In the event that .nvmrc is found in a directory, change to that version of node using NVM. --- plugins/nvm/nvm.plugin.zsh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 9dde3a26..72736c4b 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -3,3 +3,15 @@ # Load nvm if it exists [[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" + +# Look for .nvmrc in directories. If found, change to that version of node. +autoload -Uz add-zsh-hook +load-nvmrc() { + if [[ -f .nvmrc && -r .nvmrc ]]; then + nvm use --delete-prefix + elif [[ -f package.json && -r package.json ]]; then + nvm use --delete-prefix v6.11.1 + fi +} +add-zsh-hook chpwd load-nvmrc +load-nvmrc