From 054d6957e714e88ee3a382a36af0fe3c87aaf4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20Fr=C3=B6hlich?= Date: Fri, 1 Dec 2017 08:38:11 +0100 Subject: [PATCH] Update README.md Added an example for automatically executing nvm use in bash when finding a .nvmrc file. --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 3d0f07d..ac323bc 100644 --- a/README.md +++ b/README.md @@ -380,6 +380,24 @@ add-zsh-hook chpwd load-nvmrc load-nvmrc ``` +#### bash + +##### Calling `nvm use` automatically in a directory with a `.nvmrc` file + +Put this into your `$HOME/.bashrc` to call `nvm use` automatically whenever you enter a directory that contains an +`.nvmrc` file with a string telling nvm which node to `use`: + +```bash +# place this after nvm initialization! +# Redefines the shells builtin cd as function to add a hook +cd() { + # Calls the shells builtin to actually change the directory + builtin cd "$1" + # Tests for a non empty .nvmrc file and executes nvm use + [ -f ".nvmrc" ] && [ -s ".nvmrc" ] && nvm use +} +``` + ## License nvm is released under the MIT license.