Skip to content

Instantly share code, notes, and snippets.

@coltrane
Last active June 20, 2019 15:58
Show Gist options
  • Save coltrane/2f316ed96be548d3713fda04e75c4646 to your computer and use it in GitHub Desktop.
Save coltrane/2f316ed96be548d3713fda04e75c4646 to your computer and use it in GitHub Desktop.
Invokes <cmd> with proper path for vendored-node
# usage:
# withnode <cmd> [<args>...]
#
# Invokes <cmd> after adjusting PATH to include the appropriate local node/bin
# directory. `node/bin` is first located by searching up the directory tree
# starting with the current working directory.
#
function withnode() {
path=$(pwd)
while [[ $path != '/' ]]; do
if [ -x $path/node/bin/node ] ; then
break;
fi
path="$(cd $(readlink "$path"/.. || echo "$path/..") && pwd)"
done
if [ ! -x $path/node/bin/node ] ; then
1>&2 echo "no node found"
return 1
fi
if [ $# == 0 ] ; then
echo $path/node/bin
return 0
fi
PATH="$path/node/bin":$PATH "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment