2018-08-01 03:30:23 +00:00
|
|
|
unset BASH_ENV
|
2018-07-24 20:23:47 +00:00
|
|
|
|
2018-08-20 22:57:29 +00:00
|
|
|
export PATH="${HOME}/.local/bin:$PATH"
|
2018-07-24 20:23:47 +00:00
|
|
|
|
|
|
|
nac () {
|
|
|
|
local txtbld=$(tput bold)
|
|
|
|
local txtrst=$(tput sgr0)
|
|
|
|
local bldred=${txtbld}$(tput setaf 1)
|
|
|
|
local ERROR=${bldred}ERROR${txtrst}
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
echo "$ERROR: missing node environment name"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [[ ! -d "${HOME}/.local/nodeenv/$1" ]]; then
|
|
|
|
echo "$ERROR: no \"$1\" environment found in ${HOME}/.local/nodeenv"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-08-01 03:30:23 +00:00
|
|
|
__nvm_unload
|
|
|
|
__denac
|
2018-08-20 22:57:29 +00:00
|
|
|
. "${HOME}/.local/nodeenv/$1/bin/activate"
|
2018-07-24 20:23:47 +00:00
|
|
|
if [[ $? != 0 ]]; then
|
2018-08-01 03:30:23 +00:00
|
|
|
__denac
|
2018-07-24 20:23:47 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2018-08-20 22:56:01 +00:00
|
|
|
__versions
|
2018-07-25 15:13:46 +00:00
|
|
|
alias denac='deactivate_node'
|
2018-07-24 20:23:47 +00:00
|
|
|
alias deactivate_node='__denac'
|
|
|
|
case $- in
|
2018-08-01 03:30:23 +00:00
|
|
|
*i*) __npm_completion ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
export -f nac
|
|
|
|
|
|
|
|
__nac () {
|
|
|
|
local curr_word="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
local -a envs=( $(compgen -d -- "${HOME}/.local/nodeenv/$curr_word") )
|
|
|
|
COMPREPLY=( "${envs[@]##*/}" )
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
export -f __nac
|
|
|
|
complete -F __nac nac
|
|
|
|
|
|
|
|
__denac () {
|
2018-07-25 15:13:46 +00:00
|
|
|
unalias denac &> /dev/null
|
2018-07-24 20:23:47 +00:00
|
|
|
unalias deactivate_node &> /dev/null
|
|
|
|
if type deactivate_node &> /dev/null; then
|
|
|
|
deactivate_node
|
|
|
|
fi
|
2018-08-20 22:56:01 +00:00
|
|
|
. "${HOME}/.bash_env_unset_npm_config"
|
|
|
|
__versions
|
2018-07-24 20:23:47 +00:00
|
|
|
}
|
2018-08-01 03:30:23 +00:00
|
|
|
export -f __denac
|
2018-07-24 20:23:47 +00:00
|
|
|
|
|
|
|
__npm_completion () {
|
|
|
|
. <(npm completion)
|
|
|
|
}
|
|
|
|
export -f __npm_completion
|
|
|
|
|
|
|
|
nvm_load () {
|
2018-08-01 03:30:23 +00:00
|
|
|
__nvm_load
|
2018-07-24 20:23:47 +00:00
|
|
|
alias nvm_load='nvm'
|
|
|
|
alias nvm='__nvm_mask'
|
|
|
|
__nvm_mask () {
|
2018-07-25 20:17:59 +00:00
|
|
|
case "$*" in
|
2018-07-26 00:15:53 +00:00
|
|
|
unload*) __nvm_unload ;;
|
2018-08-20 22:56:01 +00:00
|
|
|
*) unalias nvm; nvm "$@"; alias nvm='__nvm_mask'; __versions ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
export -f __nvm_mask
|
|
|
|
}
|
|
|
|
export -f nvm_load
|
|
|
|
|
|
|
|
__nvm_load () {
|
2018-08-01 03:30:23 +00:00
|
|
|
__denac
|
2018-08-20 22:56:42 +00:00
|
|
|
__nvm_unload
|
2018-08-20 22:57:29 +00:00
|
|
|
. "${HOME}/.nvm/nvm.sh" &> /dev/null
|
2018-08-01 16:23:31 +00:00
|
|
|
case $- in
|
|
|
|
*i*) bash-it enable completion nvm &> /dev/null; \
|
2018-08-20 22:57:29 +00:00
|
|
|
. "${BASH_IT}/completion/available/nvm.completion.bash" ;;
|
2018-08-01 16:23:31 +00:00
|
|
|
esac
|
2018-08-01 03:30:23 +00:00
|
|
|
if [[ $(which node) = "${HOME}/.nvm/versions/"* ]]; then
|
2018-08-20 22:56:01 +00:00
|
|
|
__versions
|
2018-07-24 20:23:47 +00:00
|
|
|
case $- in
|
2018-08-01 03:30:23 +00:00
|
|
|
*i*) __npm_completion ;;
|
2018-07-24 20:23:47 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
export -f __nvm_load
|
|
|
|
|
|
|
|
__nvm_unload () {
|
|
|
|
unalias nvm_load &> /dev/null
|
|
|
|
unalias nvm &> /dev/null
|
|
|
|
unset __nvm_mask
|
|
|
|
if type nvm &> /dev/null; then
|
|
|
|
nvm unload
|
|
|
|
fi
|
2018-08-20 22:56:01 +00:00
|
|
|
__versions
|
2018-07-24 20:23:47 +00:00
|
|
|
}
|
2018-08-01 03:30:23 +00:00
|
|
|
export -f __nvm_unload
|
2018-07-24 20:23:47 +00:00
|
|
|
|
|
|
|
simple_nodeenv () {
|
2018-08-20 22:57:29 +00:00
|
|
|
pushd "$PWD" &> /dev/null
|
|
|
|
cd "${HOME}/.local/nodeenv"
|
2018-07-25 20:17:59 +00:00
|
|
|
nodeenv --prebuilt --node "$@"
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
popd &> /dev/null
|
|
|
|
return 1
|
|
|
|
fi
|
2018-07-24 20:23:47 +00:00
|
|
|
popd &> /dev/null
|
2018-07-25 20:17:59 +00:00
|
|
|
nac "$2"
|
2018-07-24 20:23:47 +00:00
|
|
|
}
|
|
|
|
export -f simple_nodeenv
|
2018-08-01 03:30:23 +00:00
|
|
|
|
2018-08-20 22:56:01 +00:00
|
|
|
__versions () {
|
2018-08-01 03:30:23 +00:00
|
|
|
if type node &> /dev/null; then
|
|
|
|
local node_version=$(node --version)
|
|
|
|
export NODE_VERSION=${node_version##v}
|
|
|
|
export NPM_VERSION=$(npm --version)
|
|
|
|
else
|
|
|
|
unset NODE_VERSION
|
|
|
|
unset NPM_VERSION
|
|
|
|
fi
|
|
|
|
}
|
2018-08-20 22:56:01 +00:00
|
|
|
export -f __versions
|
2018-08-01 03:30:23 +00:00
|
|
|
|
2018-08-08 22:16:53 +00:00
|
|
|
if [[ ! -v NODE_VIRTUAL_ENV ]]; then
|
|
|
|
nac default
|
|
|
|
fi
|