diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b291e69 --- /dev/null +++ b/LICENSE @@ -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. + diff --git a/bin/nvm-shell b/bin/nvm-shell new file mode 100755 index 0000000..e78d41f --- /dev/null +++ b/bin/nvm-shell @@ -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 "$@"