Skip to content

Instantly share code, notes, and snippets.

@harto
Last active August 29, 2015 14:16
Show Gist options
  • Save harto/4453bf0a9babb7b4c7d2 to your computer and use it in GitHub Desktop.
Save harto/4453bf0a9babb7b4c7d2 to your computer and use it in GitHub Desktop.
$PATH manager for npm projects
npm-activate() {
npm-deactivate
export __NPM_PROJECT_BINS=$(__npm-project-bins $1)
export PATH=$__NPM_PROJECT_BINS:$PATH
}
npm-deactivate() {
if [[ -n $__NPM_PROJECT_BINS ]]; then
export PATH=${PATH#$__NPM_PROJECT_BINS:}
fi
}
__npm-project-bins() {
local npm_project_dir=${1:-.}
(cd $npm_project_dir && npm bin)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment