Merge pull request #508 from creationix/nvm_copy_packages_not_npm

Don't copy `npm` with `nvm copy-packages`
diff --git a/nvm.sh b/nvm.sh
index 7f734fe..e45a53e 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -785,15 +785,13 @@
         nvm help
         return 127
       fi
-      VERSION=$(nvm_version "$2")
-      local ROOT
-      ROOT=$(nvm use $VERSION && npm -g root)
+      VERSION="$(nvm_version "$2")"
 
       # declare local INSTALLS first, otherwise it doesn't work in zsh
       local INSTALLS
-      INSTALLS=$(nvm use $VERSION > /dev/null && npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | \grep -o -e '/[^/]*$' | cut -c 2- | xargs)
+      INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
 
-      npm install -g --quiet $INSTALLS
+      echo "$INSTALLS" | xargs npm install -g --quiet
     ;;
     "clear-cache" )
       rm -f $NVM_DIR/v* "$(nvm_version_dir)" 2>/dev/null
diff --git a/test/slow/nvm copy-packages/should work as expected b/test/slow/nvm copy-packages/should work as expected
index 21f10df..e599609 100755
--- a/test/slow/nvm copy-packages/should work as expected
+++ b/test/slow/nvm copy-packages/should work as expected
@@ -6,15 +6,15 @@
 
 nvm use 0.10.28
 
-EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-server jshint marked node-gyp npm recursive-blame uglify-js yo"
+EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-server jshint marked node-gyp recursive-blame uglify-js yo"
 
-npm install -g --quiet $EXPECTED_PACKAGES
+echo "$EXPECTED_PACKAGES" | xargs npm install -g --quiet
 
 nvm use 0.10.29
-ORIGINAL_PACKAGES=$(npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | grep -o -e '/[^/]*$' | cut -c 2- | sort | uniq | xargs)
+ORIGINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | sort | uniq | xargs)
 
 nvm copy-packages 0.10.28
-FINAL_PACKAGES=$(npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | grep -o -e '/[^/]*$' | cut -c 2- | sort | uniq | xargs)
+FINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | sort | uniq | xargs)
 
 [ "$FINAL_PACKAGES" = "$EXPECTED_PACKAGES" ] || die "final packages ($FINAL_PACKAGES) did not match expected packages ($EXPECTED_PACKAGES)"
 [ "$ORIGINAL_PACKAGES" != "$FINAL_PACKAGES" ] || die "original packages matched final packages ($ORIGINAL_PACKAGES)"