/fast-zsh-nvm

A speed-optimized ZSH plugin for loading NVM.

Primary LanguageShellMIT LicenseMIT

Fast-ZSH-NVM

Overview

A ZSH plugin to initialize NVM quickly when a new terminal opens.

If AUTO_LOAD_NVMRC_FILES is set to true, this plugin also runs nvm use automatically whenever you enter a directory that contains an .nvmrc file (which NVM reads to discover what version of node to use in that location).

Why?

Other NVM-loading scripts I've seen (including the default technique provided in NVM itself) have been widely reported to be slow.

Thanks to some feedback from NVM's main author and another helpful developer, there are a couple ways to speed this process up (the --no-use option and asynchronous loading). I just compiled both into an easy-to-install package.

Integration with plugin managers

fast-zsh-nvm requires the mafredri/zsh-async package, so be sure to install both in your plugin manager of choice.

Update your .zshrc file with the following two lines (order matters):

antibody bundle mafredri/zsh-async
antibody bundle allanjamesvestal/fast-zsh-nvm

Update your .zshrc file with the following two lines (order matters). Do not use the antigen theme function.

antibody bundle mafredri/zsh-async
antibody bundle allanjamesvestal/fast-zsh-nvm
zgen load mafredri/zsh-async
zgen load allanjamesvestal/fast-zsh-nvm

Update your .zshrc file with the following two lines:

zplug mafredri/zsh-async, from:github
zplug allanjamesvestal/fast-zsh-nvm, from:github

Configuration

fast-zsh-nvm has two configuration options. Each can be triggered by setting the corresponding environment variable to true.

AUTO_LOAD_NVMRC_FILES listens every time you change directories. If the new directory has an .nvmrc file, this option will automatically switch to the correct node verson for that folder.

LOAD_NVMRC_ON_INIT extends the plugin to also run that auto-loading behavior just after the terminal session starts. This is disabled by default, as it adds significantly to the initial load time if your starting directory contains a .nvmrc file.