Update example bash script to use nvm use on shell open

This commit is contained in:
GARY PARKER 2020-02-21 08:26:24 -05:00
parent 8093dbeacd
commit b93a27ed03

View File

@ -458,8 +458,12 @@ find-up () {
echo "$path" echo "$path"
} }
cdnvm(){ cdnvm() {
cd "$@"; cd "$@";
nvmUse
}
nvmUse() {
nvm_path=$(find-up .nvmrc | tr -d '[:space:]') nvm_path=$(find-up .nvmrc | tr -d '[:space:]')
# If there are no .nvmrc file, use the default nvm version # If there are no .nvmrc file, use the default nvm version
@ -500,11 +504,15 @@ cdnvm(){
fi fi
fi fi
} }
alias cd='cdnvm' alias cd='cdnvm'
nvmUse
``` ```
This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version. This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version.
It will also call `nvm use` when a new terminal window is opened (e.g. opening a terminal in your IDE).
#### zsh #### zsh
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file ##### Calling `nvm use` automatically in a directory with a `.nvmrc` file