-
-
Save OwenChia/65e5c1be8aeb62818c5151ff9b0cd0de to your computer and use it in GitHub Desktop.
nodevenv
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
#!/usr/bin/env sh | |
node_activate() { | |
local _DIRNAME=${PWD##*/} | |
if ! grep -qi $_DIRNAME <<< $PS1; then | |
_OLD_PS1=$PS1 | |
export PS1="($_DIRNAME) $PS1" | |
fi | |
if ! grep -qi node_modules <<< $PATH; then | |
_OLD_PATH=$PATH | |
export PATH=${PWD}/node_modules/.bin/:$PATH | |
fi | |
} | |
node_deactivate() { | |
export PS1=$_OLD_PS1 | |
export PATH=$_OLD_PATH | |
unset -v _OLD_PS1 _OLD_PATH | |
unset -f node_activate node_deactivate | |
unalias deactivate | |
} | |
node_activate | |
alias deactivate=node_deactivate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment