Skip to content

Instantly share code, notes, and snippets.

@OwenChia
Created July 15, 2018 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OwenChia/65e5c1be8aeb62818c5151ff9b0cd0de to your computer and use it in GitHub Desktop.
Save OwenChia/65e5c1be8aeb62818c5151ff9b0cd0de to your computer and use it in GitHub Desktop.
nodevenv
#!/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