$PATH manager for npm projects

I wrote this dumb script to add npm project binaries to $PATH. These binaries live in $project/node_modules/.bin, which makes for some pretty clunky invocations, e.g. node_nodules/.bin/jsx --watch src build, instead of jsx --watch src build.

It's possible to add ./node_modules/.bin directly to $PATH, but that doesn't work if you're in a project subdirectory. It's probably also bad from a security perspective.

npm-activate() {
  export NPMPROJECTBINS=$(npm-project-bins $1)

npm-deactivate() { if [[ -n $NPMPROJECTBINS ]]; then export PATH=${PATH#$NPMPROJECTBINS:} fi }

_npm-project-bins() { local npmprojectdir=${1:-.} (cd $npmproject_dir && npm bin) }