Last active
May 22, 2018 22:01
-
-
Save Francois-Esquire/bfcfbabada71dbf6da1904b5db1ff69a to your computer and use it in GitHub Desktop.
loading ./node_modules/.bin on the fly | only possible with zsh terminals, avoids setting traps to cd, etc...
This file contains hidden or 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
# for loading node module bin files into PATH | |
NPM_LOCAL_MODULES=/dev/null | |
function npm_bin_loader() { | |
CURRENT_NPM_MODULE=$NPM_LOCAL_MODULES | |
if [ -d "node_modules" ] | |
then | |
NPM_LOCAL_MODULES="$(pwd)/node_modules/.bin" | |
else | |
NPM_LOCAL_MODULES=/dev/null | |
fi | |
if [ $NPM_LOCAL_MODULES != $CURRENT_NPM_MODULE ] | |
then | |
PATH=$(echo $PATH | sed -e 's|'$CURRENT_NPM_MODULE'|'$NPM_LOCAL_MODULES'|g') | |
fi | |
# just to check the path | |
echo $PATH | |
} | |
# adding our helper to the change pwd hook | |
chpwd_functions+=("npm_bin_loader") | |
# export the path | |
export PATH=$NPM_LOCAL_MODULES:$PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment