Last active
June 20, 2019 15:58
-
-
Save coltrane/2f316ed96be548d3713fda04e75c4646 to your computer and use it in GitHub Desktop.
Invokes <cmd> with proper path for vendored-node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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