embark-docker/env/.bash_env

145 lines
3.2 KiB
Bash
Raw Normal View History

2018-08-01 03:30:23 +00:00
unset BASH_ENV
if [[ :$PATH: != *:"${HOME}/.local/bin":* ]] ; then
export PATH="${HOME}/.local/bin:$PATH"
fi
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
__denac
2018-08-21 00:31:22 +00:00
__nvm_unload
2018-08-20 22:57:29 +00:00
. "${HOME}/.local/nodeenv/$1/bin/activate"
if [[ $? != 0 ]]; then
2018-08-01 03:30:23 +00:00
__denac
return 1
fi
export -f deactivate_node
export _OLD_NODE_PATH
export _OLD_NODE_VIRTUAL_PATH
export _OLD_NODE_VIRTUAL_PS1
export _OLD_npm_config_prefix
export _OLD_NPM_CONFIG_PREFIX
alias denac='deactivate_node'
alias deactivate_node='__denac'
__versions
case $- in
2018-08-01 03:30:23 +00:00
*i*) __npm_completion ;;
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 () {
unalias denac &> /dev/null
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-08-01 03:30:23 +00:00
export -f __denac
__npm_completion () {
. <(npm completion)
}
export -f __npm_completion
nvm_load () {
2018-08-01 03:30:23 +00:00
__nvm_load
alias nvm_load='nvm'
alias nvm='__nvm_mask'
__nvm_mask () {
2018-07-25 20:17:59 +00:00
case "$*" in
unload*) __nvm_unload ;;
2018-08-20 22:56:01 +00:00
*) unalias nvm; nvm "$@"; alias nvm='__nvm_mask'; __versions ;;
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
case $- in
2018-08-01 03:30:23 +00:00
*i*) __npm_completion ;;
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-08-01 03:30:23 +00:00
export -f __nvm_unload
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
popd &> /dev/null
2018-07-25 20:17:59 +00:00
nac "$2"
}
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
if [[ ! -v NODE_VIRTUAL_ENV ]]; then
nac default
else
if ! type denac &> /dev/null; then
alias denac='deactivate_node'
alias deactivate_node='__denac'
case $- in
*i*) __npm_completion ;;
esac
fi
fi