Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Zsh plugin for installing, updating and loading nvm

License

NotificationsYou must be signed in to change notification settings

lukechilds/zsh-nvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zsh plugin for installing, updating and loadingnvm

GitHub DonateBitcoin DonateLightning Donate

nvm is an awesome tool but it can be kind of a pain to install and keep up to date. This zsh plugin allows you to quickly setupnvm once, save it in your dotfiles, then never worry about it again.

The plugin will install the latest stable release ofnvm if you don't already have it, and then automaticallysource it for you. You can upgradenvm to the latest version whenever you want without losing your installednode versions by runningnvm upgrade.

Although this is written as a zsh plugin, it also works with bash if you follow themanual installation instructions.

Usage

Once the plugin's installednvm will be available. You'll probably want to load this as one of your first plugins sonode/npm is available for any other plugins that may require them.

zsh-nvm also wrapsnvm in some additional functionality.

Upgrade

If you want to upgrade to the latest release ofnvm:

% nvm upgradeInstalled version is v0.31.0Checking latest version of nvm...Updating to v0.31.3...Previous HEAD position was 2176894... v0.31.0HEAD is now at 56417f8... v0.31.3

Revert

If an upgrade breaks something don't worry, reverting back to the previously installed version is simple:

% nvm revertInstalled version is v0.31.3Reverting to v0.31.0...Previous HEAD position was 56417f8... v0.31.3HEAD is now at 2176894... v0.31.0

Install

You can install the latest Node.js nightlies or release candidates withnvm install nightly|rc. Aliases will automatically be created so you can easilynvm use nightly|rc in the future:

% nvm install rcDownloading and installing node v8.0.0-rc.1...Downloading https://nodejs.org/download/rc//v8.0.0-rc.1/node-v8.0.0-rc.1-darwin-x64.tar.xz...######################################################################## 100.0%Computing checksum with shasum -a 256Checksums matched!Now using node v8.0.0-rc.1 (npm v5.0.0-beta.56)rc -> v8.0.0-rc.1Clearing mirror cache...Done!

Note: This is a bit of a hack and leaving rc|nightly versions installed may break nvm when it eventually supports them itself. It's recommended that you don't leave the these versions of Node.js installed. Install them, test/play with them and then uninstall them when you're done.

Options

Custom Directory

You can specify a custom directory to use withnvm by exporting theNVM_DIR environment variable. It must be set beforezsh-nvm is loaded.

For example, if you are using antigen, you would put the following in your.zshrc:

export NVM_DIR="$HOME/.custom-nvm-dir"antigen bundle lukechilds/zsh-nvm

Note: Ifnvm doesn't exist in this directory it'll be automatically installed when you start a session.

Nvm Completion

nvm comes with a default bash_completion profile. If you want to enable it, you can do it by exporting theNVM_COMPLETION environment variable and setting it totrue. It must be set beforezsh-nvm is loaded.

For example, if you are using antigen, you would put the following in your.zshrc:

# Export nvm completion settings for zsh-nvm pluginexport NVM_COMPLETION=trueantigen bundle lukechilds/zsh-nvm

Lazy Loading

If you findnvm adds too much lag to your shell startup you can enable lazy loading by exporting theNVM_LAZY_LOAD environment variable and setting it totrue. It must be set beforezsh-nvm is loaded.

Lazy loading is around 70x faster (874ms down to 12ms for me), however the first time you runnvm,npm,node or a global module you'll get a slight delay whilenvm loads first. You'll only get this delay once per session.

For example, if you are using antigen, you would put the following in your.zshrc:

export NVM_LAZY_LOAD=trueantigen bundle lukechilds/zsh-nvm

Performance comparison:

%time (source"$NVM_DIR/nvm.sh")(source"$NVM_DIR/nvm.sh"; )  0.58s user 0.37s system 109% cpu 0.874 total%time (_zsh_nvm_lazy_load)( _zsh_nvm_lazy_load; )  0.01s user 0.01s system 168% cpu 0.012 total

Extra commands to trigger lazy loading

By default lazy loading nvm is triggered by running thenvm,node,npm commands or any installed npm global binaries.If you want to trigger the lazy loading via extra arbitrary commands you can defineNVM_LAZY_LOAD_EXTRA_COMMANDS and set it to an array of commands as strings.This can be usefull if programs are not in the above list of binaries but do depend on the availability ofnode, e.g. a vim plugin.

export NVM_LAZY_LOAD_EXTRA_COMMANDS=('vim')vim --version#node is now loaded

Don't autoload node

By default whennvm is loaded it'll automatically runnvm use default and load your defaultnode version along withnpm and any global modules. You can disable this behaviour by exporting theNVM_NO_USE environment variable and setting it totrue. It must be set beforezsh-nvm is loaded.

If you enable this option you will then need to manually runnvm use <version> before you can usenode.

For example, if you are using antigen, you would put the following in your.zshrc:

export NVM_NO_USE=trueantigen bundle lukechilds/zsh-nvm

Auto use

If you have lots of projects with an.nvmrc file you may find the auto use option helpful. If it's enabled, when youcd into a directory with an.nvmrc file,zsh-nvm will automatically load or install the required node version in.nvmrc. You can enable it by exporting theNVM_AUTO_USE environment variable and setting it totrue. It must be set beforezsh-nvm is loaded.

If you enable this option and don't havenvm loaded in the current session (NVM_LAZY_LOAD orNVM_NO_USE) it won't work until you've loadednvm.

For example, if you are using antigen, you would put the following in your.zshrc:

export NVM_AUTO_USE=trueantigen bundle lukechilds/zsh-nvm

Installation

UsingAntigen

Bundlezsh-nvm in your.zshrc

antigen bundle lukechilds/zsh-nvm

Usingzplug

Loadzsh-nvm as a plugin in your.zshrc

zplug"lukechilds/zsh-nvm"

Usingzgen

Include the load command in your.zshrc

zgen load lukechilds/zsh-nvm

As anOh My ZSH! custom plugin

Clonezsh-nvm into your custom plugins repo

git clone https://github.com/lukechilds/zsh-nvm~/.oh-my-zsh/custom/plugins/zsh-nvm

Then load as a plugin in your.zshrc

plugins+=(zsh-nvm)

Keep in mind that plugins need to be added beforeoh-my-zsh.sh is sourced.

Manually

Clone this repository somewhere (~/.zsh-nvm for example)

git clone https://github.com/lukechilds/zsh-nvm.git~/.zsh-nvm

Then source it in your.zshrc (or.bashrc)

source~/.zsh-nvm/zsh-nvm.plugin.zsh

Tests

To run the tests you'll need to installUrchin. You'll also need to run the tests in an environment that doesn't already havenode ornvm loaded.

You can removenvm from the existing session with:

nvm deactivate&& nvm unload

Run the tests with:

urchin -s zsh tests

Related

License

MIT © Luke Childs


[8]ページ先頭

©2009-2025 Movatter.jp