ported rvm-shell from RVM into nvm as nvm-shell.

This commit is contained in:
Yamashita Yuu 2011-06-24 03:22:45 +09:00 committed by Geisha Tokyo Administrator
parent 77ba1f5902
commit 7f08fa41da
2 changed files with 113 additions and 0 deletions

14
LICENSE Normal file
View File

@ -0,0 +1,14 @@
Copyright (c) 2009-2011 Wayne E. Seguin
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

99
bin/nvm-shell Executable file
View File

@ -0,0 +1,99 @@
#!/usr/bin/env bash
export HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
if (( ${nvm_ignore_nvmrc:=0} == 0 ))
then
for nvmrc in /etc/nvmrc "$HOME/.nvmrc"
do
if [[ -f "$nvmrc" ]]
then
if \grep '^\s*nvm .*$' "$nvmrc" >/dev/null 2>&1
then
printf "\nError: $nvmrc is for nvm settings only.\nnvm CLI may NOT be called from within $nvmrc. \nSkipping the loading of $nvmrc"
return 1
else
source "$nvmrc"
fi
fi
done
fi
if [[ -z "${nvm_path:-}" ]]
then
# Set the default sandboxed value.
# TODO: Alter the variable names to make sense
if [[ -z "${nvm_user_install_flag:-}" ]]
then
if (( UID == 0 )) ||
[[ -n "${nvm_prefix:-}" && "${nvm_prefix:-}" != "${HOME}" ]]
then
nvm_user_install_flag=0
else
nvm_user_install_flag=1
fi
fi
if [[ -z "${nvm_prefix:-}" ]]
then
if (( ${nvm_user_install_flag:=0} == 0 ))
then
nvm_prefix="/usr/local"
elif [[ -n "$HOME" ]]
then
nvm_prefix="$HOME"
else
echo "No \$nvm_prefix was provided and "
echo "$(id | \sed -e's/^[^(]*(//' -e 's/).*//') has no \$HOME defined."
echo "Halting loading of NVM."
nvm_load_nvm=0
fi
fi
true "${nvm_prefix/nvm/scripts}" # Fix nvm_prefix changes, older installs.
if [[ -z "${nvm_path:-}" ]]
then
if [[ "$nvm_prefix" = "$HOME" ]]
then
nvm_path="${nvm_prefix}/.nvm"
else
nvm_path="${nvm_prefix}/nvm"
fi
fi
export nvm_path="${nvm_path%%+(\/)}"
fi
__nvm_shell_lookup_script()
{
local relative_scripts_dir
relative_scripts_dir="$(dirname -- "$(dirname -- "$0")")"
for directory in "$HOME/.nvm" "/usr/local/nvm" "$relative_scripts_dir"; do
if [[ -d "$directory" && -s "$directory/nvm.sh" ]]; then
echo "$directory/nvm.sh"
return
fi
done
}
if [[ -n "$1" && ! -f "$1" && -n "$(echo "$1" | \grep -v '^-')" ]]; then
nvm_shell_node_string="$1"
shift
fi
nvm_shell_nvm_path="$(__nvm_shell_lookup_script)"
if [[ -n "$nvm_shell_nvm_path" ]]; then
source "$nvm_shell_nvm_path"
# Setup as expected.
if [[ -n "$nvm_shell_node_string" ]]; then
nvm use "$nvm_shell_node_string"
if [[ "$?" -gt 0 ]]; then
echo "Error: NVM was unable to use '$nvm_shell_node_string'" 1>&2
exit 1
fi
else
nvm use default >/dev/null 2>&1
fi
fi
exec bash "$@"