Fix shell startup time

Makes nvm a function that gets replaced by the real nvm function.
This means that nvm.sh will only get sourced if it is really
needed, removing a noticable shell startup delay.

After this initialization call, the nvm function will be replaced
by the function that gets loaded from `$INSTALL_DIR/nvm.sh`.

Right after the bootstapping, first run, the command line options
will be passed to the newly sourced nvm function. For the user,
this change is transparent.

Tested with dash, zsh5 and bash4 on my machine. Travis does not
complain.

The following snippet will be added to the shell's start-up file:

``` sh
export NVM_DIR="$HOME/.nvm"
nvm() {
  echo Loading nvm for first use in this shell >/dev/stderr
  [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
  nvm "$@"
}
```
This commit is contained in:
Joep van Delft 2016-09-10 22:11:20 +02:00
parent 404467aceb
commit f91830be31

View File

@ -289,11 +289,8 @@ nvm_do_install() {
SOURCE_STR="\nexport NVM_DIR=\"$INSTALL_DIR\"" SOURCE_STR="\nexport NVM_DIR=\"$INSTALL_DIR\""
SOURCE_STR="$SOURCE_STR\nnvm() {\n echo Loading nvm for first use in this shell >/dev/stderr" SOURCE_STR="$SOURCE_STR\nnvm() {\n echo Loading nvm for first use in this shell >/dev/stderr"
SOURCE_STR="$SOURCE_STR\n [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads nvm" SOURCE_STR="$SOURCE_STR\n [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
SOURCE_STR="$SOURCE_STR\n nvm \"\$@\"\n}" SOURCE_STR="$SOURCE_STR\n nvm \"\$@\"\n}"
echo $SOURCE_STR
}
if [ -z "${NVM_PROFILE-}" ] ; then if [ -z "${NVM_PROFILE-}" ] ; then
echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."