From 404467aceb22287be492ab057432179ba6147e9f Mon Sep 17 00:00:00 2001 From: Joep van Delft Date: Sat, 10 Sep 2016 01:10:07 +0200 Subject: [PATCH 1/2] Fix shell startup time makes nvm a function that gets replaced by the real nvm function. After that, it will get called with the specified arguments. Calls after this initialization call, will use the original nvm shell function. By introducing this indirection, shell startup time is significantly improved. --- install.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index b1a2928..d24e419 100755 --- a/install.sh +++ b/install.sh @@ -287,7 +287,13 @@ nvm_do_install() { local INSTALL_DIR INSTALL_DIR="$(nvm_install_dir)" - SOURCE_STR="\nexport NVM_DIR=\"$INSTALL_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm\n" + 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\n [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads nvm" + SOURCE_STR="$SOURCE_STR\n nvm \"\$@\"\n}" + echo $SOURCE_STR +} + if [ -z "${NVM_PROFILE-}" ] ; then echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." From f91830be31eeedc0d28f911a0cd415a697ccb171 Mon Sep 17 00:00:00 2001 From: Joep van Delft Date: Sat, 10 Sep 2016 22:11:20 +0200 Subject: [PATCH 2/2] 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 "$@" } ``` --- install.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/install.sh b/install.sh index d24e419..958b4dc 100755 --- a/install.sh +++ b/install.sh @@ -289,11 +289,8 @@ nvm_do_install() { 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\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}" - echo $SOURCE_STR -} - if [ -z "${NVM_PROFILE-}" ] ; then echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."