Skip to content

Commit

Permalink
Load NVM lazily
Browse files Browse the repository at this point in the history
$NVM_DIR/nvm.sh is a slow script and has doubled time to load zsh.
In this commit, the script is not loaded until required.
cf. nvm-sh/nvm#1277
  • Loading branch information
eudika committed Aug 30, 2020
1 parent c8d794e commit 4010053
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/node/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

# Load manually installed NVM into the shell session.
if [[ -s "${NVM_DIR:=$HOME/.nvm}/nvm.sh" ]]; then
source "${NVM_DIR}/nvm.sh"
# Add latest node to the path.
path=("$NVM_DIR/versions/node/$(ls $NVM_DIR/versions/node | sort -V | tail -n1)/bin/": $path)
# Load NVM lazily.
nvm() {
unset nvm;
# This line is very slow.
source "$NVM_DIR/nvm.sh"
nvm "$@"
}

# Load package manager installed NVM into the shell session.
elif (( $+commands[brew] )) && \
Expand Down

0 comments on commit 4010053

Please sign in to comment.