diff --git a/nvm.sh b/nvm.sh index 54a01c1..f8aea57 100644 --- a/nvm.sh +++ b/nvm.sh @@ -358,6 +358,16 @@ nvm_is_iojs_version() { [ "_$(echo "$1" | cut -c1-5)" = "_iojs-" ] } +nvm_strip_iojs_prefix() { + local NVM_IOJS_PREFIX + NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" + if [ "_$1" = "_$NVM_IOJS_PREFIX" ]; then + echo + else + echo "$1" | command sed "s/^$NVM_IOJS_PREFIX-//" + fi +} + nvm_ls() { local PATTERN PATTERN="$1" @@ -1202,6 +1212,7 @@ nvm() { "unload" ) unset -f nvm nvm_print_versions nvm_checksum \ nvm_iojs_prefix nvm_node_prefix \ + nvm_strip_iojs_prefix \ nvm_is_iojs_version \ nvm_ls_remote nvm_ls nvm_remote_version \ nvm_version nvm_rc_version \ diff --git a/test/fast/Unit tests/nvm_strip_iojs_prefix b/test/fast/Unit tests/nvm_strip_iojs_prefix new file mode 100755 index 0000000..782fbc4 --- /dev/null +++ b/test/fast/Unit tests/nvm_strip_iojs_prefix @@ -0,0 +1,10 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +[ "_$(nvm_strip_iojs_prefix iojs)" = "_" ] || die '"nvm_strip_iojs_prefix iojs" did not return an empty string' +[ "_$(nvm_strip_iojs_prefix iojs-)" = "_" ] || die '"nvm_strip_iojs_prefix iojs-" did not return an empty string' +[ "_$(nvm_strip_iojs_prefix iojs-foo)" = "_foo" ] || die '"nvm_strip_iojs_prefix iojs-foo" did not return "foo"' +[ "_$(nvm_strip_iojs_prefix iojsfoo)" = "_iojsfoo" ] || die '"nvm_strip_iojs_prefix iojsfoo" did not return "iojsfoo"'