embark-docker/.bash_env

144 lines
3.7 KiB
Bash

unset BASH_ENV
# we don't need to run more than once
if [[ -v embark_docker_embark_user_BASH_ENV ]]; then
return
fi
export embark_docker_embark_user_BASH_ENV=
export embark_docker_embark_user_npm_bak_config_prefix=${HOME}/.npm-packages
export npm_config_prefix=$embark_docker_embark_user_npm_bak_config_prefix
export NPM_CONFIG_PREFIX=$npm_config_prefix
export embark_docker_embark_user_PATH_with_LOCALBIN=${HOME}/.local/bin:$PATH
export embark_docker_embark_user_PATH_with_NPM=$NPM_CONFIG_PREFIX/bin:$embark_docker_embark_user_PATH_with_LOCALBIN
export PATH=$embark_docker_embark_user_PATH_with_NPM
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
____nvm_unload
____denac
export PATH=$embark_docker_embark_user_PATH_with_LOCALBIN
. ${HOME}/.local/nodeenv/$1/bin/activate
if [[ $? != 0 ]]; then
____denac
return 1
fi
alias deactivate_node='__denac'
case $- in
*i*) __npm_completion \
&& echo "Now using NODEENV node $(node --version) (npm v$(npm --version))";;
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 () {
____denac
case $- in
*i*) echo "Now using system node $(node --version) (npm v$(npm --version))";;
esac
}
export -f __denac
____denac () {
unalias deactivate_node &> /dev/null
if type deactivate_node &> /dev/null; then
deactivate_node
fi
export PATH=$embark_docker_embark_user_PATH_with_NPM
}
export -f ____denac
__npm_completion () {
. <(npm completion)
}
export -f __npm_completion
nvm_load () {
__nvm_load
alias nvm_load='nvm'
alias nvm='__nvm_mask'
__nvm_mask () {
case $* in
unload*) shift 1; __nvm_unload;;
*) unalias nvm; nvm "$@"; alias nvm='__nvm_mask';;
esac
}
export -f __nvm_mask
}
export -f nvm_load
__nvm_load () {
____nvm_unload
____denac
export PATH=$embark_docker_embark_user_PATH_with_LOCALBIN
. ${HOME}/.bash_env_nvm_load
. ${HOME}/.nvm/nvm.sh &> /dev/null
if [[ (-z $(nvm alias default)) && ($1 != "no-auto-lts") ]]; then
case $- in
*i*) nvm install --lts;;
*) nvm install --lts &> /dev/null;;
esac
local auto_lts=
fi
case $- in
*i*) __npm_completion;;
esac
if [[ (! -v auto_lts) \
&& ($(which node) = "${HOME}/.nvm/versions/"*) ]]; then
case $- in
*i*) echo "Now using NVM node $(node --version) (npm v$(npm --version))";;
esac
fi
}
export -f __nvm_load
__nvm_unload () {
____nvm_unload
case $- in
*i*) echo "Now using system node $(node --version) (npm v$(npm --version))";;
esac
}
export -f __nvm_unload
____nvm_unload () {
unalias nvm_load &> /dev/null
unalias nvm &> /dev/null
unset __nvm_mask
if type nvm &> /dev/null; then
nvm unload
fi
export PATH=$embark_docker_embark_user_PATH_with_NPM
. ${HOME}/.bash_env_nvm_unload
}
export -f ____nvm_unload
simple_nodeenv () {
pushd $PWD &> /dev/null
cd ${HOME}/.local/nodeenv
nodeenv --prebuilt --node $@
popd &> /dev/null
unalias nac &> /dev/null
nac $2
}
export -f simple_nodeenv