Adding `nvm_num_version_groups`

master
Jordan Harband 2014-09-16 08:36:05 -07:00
parent 15b3e7b6a8
commit 4b2bc0be08
2 changed files with 35 additions and 0 deletions

14
nvm.sh
View File

@ -181,6 +181,20 @@ nvm_format_version() {
echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
}
nvm_num_version_groups() {
local VERSION
VERSION="$1"
if [ -z "$VERSION" ]; then
echo "0"
return
fi
local NVM_NUM_DOTS
NVM_NUM_DOTS=$(echo "$VERSION" | sed -e 's/^v//' | sed -e 's/\.$//' | sed -e 's/[^\.]//g')
local NVM_NUM_GROUPS
NVM_NUM_GROUPS=".$NVM_NUM_DOTS"
echo "${#NVM_NUM_GROUPS}"
}
nvm_strip_path() {
echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
}

View File

@ -0,0 +1,21 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
[ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0"
[ "~$(nvm_num_version_groups a)" = "~1" ] || die "one letter should give 1"
[ "~$(nvm_num_version_groups 1)" = "~1" ] || die "1 should give 1"
[ "~$(nvm_num_version_groups v1)" = "~1" ] || die "v1 should give 1"
[ "~$(nvm_num_version_groups v1.)" = "~1" ] || die "v1. should give 1"
[ "~$(nvm_num_version_groups 1.2)" = "~2" ] || die "1.2 should give 2"
[ "~$(nvm_num_version_groups v1.2)" = "~2" ] || die "v1.2 should give 2"
[ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2"
[ "~$(nvm_num_version_groups 1.2.3)" = "~3" ] || die "1.2.3 should give 3"
[ "~$(nvm_num_version_groups v1.2.3)" = "~3" ] || die "v1.2.3 should give 3"
[ "~$(nvm_num_version_groups v1.2.3.)" = "~3" ] || die "v1.2.3. should give 3"