Adding `nvm_version_dir`

master
Jordan Harband 2014-08-19 01:53:39 -07:00
parent 42786630a1
commit 9068dda110
2 changed files with 24 additions and 0 deletions

13
nvm.sh
View File

@ -95,6 +95,19 @@ nvm_rc_version() {
fi
}
nvm_version_dir() {
local NVM_USE_NEW_DIR
NVM_USE_NEW_DIR="$1"
if [ -z "$NVM_USE_NEW_DIR" ] || [ "$NVM_USE_NEW_DIR" = "new" ]; then
echo "$NVM_DIR/versions"
elif [ "$NVM_USE_NEW_DIR" = "old" ]; then
echo "$NVM_DIR"
else
echo "unknown version dir" >&2
return 3
fi
}
nvm_version_path() {
local VERSION
VERSION="$1"

View File

@ -0,0 +1,11 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
[ "$(nvm_version_dir)" = "$NVM_DIR/versions" ] || die '"nvm_version_dir" did not return new dir path'
[ "$(nvm_version_dir new)" = "$(nvm_version_dir)" ] || die '"nvm_version_dir new" did not return new dir path'
[ "$(nvm_version_dir old)" = "$NVM_DIR" ] || die '"nvm_version_dir old" did not return old dir path'
[ "$(nvm_version_dir foo 2>&1)" = "unknown version dir" ] || die '"nvm_version_dir foo" did not error out'