• Stars
    star
    2,077
  • Rank 21,407 (Top 0.5 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zsh plugin for installing, updating and loading nvm

zsh-nvm Build Status

Zsh plugin for installing, updating and loading nvm

GitHub Donate Bitcoin Donate Lightning 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 setup nvm once, save it in your dotfiles, then never worry about it again.

The plugin will install the latest stable release of nvm if you don't already have it, and then automatically source it for you. You can upgrade nvm to the latest version whenever you want without losing your installed node versions by running nvm upgrade.

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

Usage

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

zsh-nvm also wraps nvm in some additional functionality.

Upgrade

If you want to upgrade to the latest release of nvm:

% nvm upgrade
Installed version is v0.31.0
Checking latest version of nvm...
Updating to v0.31.3...
Previous HEAD position was 2176894... v0.31.0
HEAD 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 revert
Installed version is v0.31.3
Reverting to v0.31.0...
Previous HEAD position was 56417f8... v0.31.3
HEAD is now at 2176894... v0.31.0

Install

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

% nvm install rc
Downloading 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 256
Checksums matched!
Now using node v8.0.0-rc.1 (npm v5.0.0-beta.56)
rc -> v8.0.0-rc.1
Clearing 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 with nvm by exporting the NVM_DIR environment variable. It must be set before zsh-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: If nvm 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 the NVM_COMPLETION environment variable and setting it to true. It must be set before zsh-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 plugin
export NVM_COMPLETION=true
antigen bundle lukechilds/zsh-nvm

Lazy Loading

If you find nvm adds too much lag to your shell startup you can enable lazy loading by exporting the NVM_LAZY_LOAD environment variable and setting it to true. It must be set before zsh-nvm is loaded.

Lazy loading is around 70x faster (874ms down to 12ms for me), however the first time you run nvm, npm, node or a global module you'll get a slight delay while nvm 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=true
antigen 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 the nvm, node, npm commands or any installed npm global binaries. If you want to trigger the lazy loading via extra arbitrary commands you can define NVM_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 of node, e.g. a vim plugin.

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

Don't autoload node

By default when nvm is loaded it'll automatically run nvm use default and load your default node version along with npm and any global modules. You can disable this behaviour by exporting the NVM_NO_USE environment variable and setting it to true. It must be set before zsh-nvm is loaded.

If you enable this option you will then need to manually run nvm use <version> before you can use node.

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

export NVM_NO_USE=true
antigen 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 you cd 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 the NVM_AUTO_USE environment variable and setting it to true. It must be set before zsh-nvm is loaded.

If you enable this option and don't have nvm loaded in the current session (NVM_LAZY_LOAD or NVM_NO_USE) it won't work until you've loaded nvm.

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

export NVM_AUTO_USE=true
antigen bundle lukechilds/zsh-nvm

Installation

Using Antigen

Bundle zsh-nvm in your .zshrc

antigen bundle lukechilds/zsh-nvm

Using zplug

Load zsh-nvm as a plugin in your .zshrc

zplug "lukechilds/zsh-nvm"

Using zgen

Include the load command in your .zshrc

zgen load lukechilds/zsh-nvm

As an Oh My ZSH! custom plugin

Clone zsh-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 before oh-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 install Urchin. You'll also need to run the tests in an environment that doesn't already have node or nvm loaded.

You can remove nvm from the existing session with:

nvm deactivate && nvm unload

Run the tests with:

urchin -s zsh tests

Related

License

MIT © Luke Childs

More Repositories

1

reverse-shell

Reverse Shell as a Service
JavaScript
1,732
star
2

dockerpi

A Virtualised Raspberry Pi inside a Docker image
Dockerfile
1,677
star
3

merge-images

Easily compose images together without messing around with canvas
JavaScript
1,611
star
4

gifgen

Simple high quality GIF encoding
Shell
527
star
5

zsh-better-npm-completion

Better completion for npm
Shell
450
star
6

when-dom-ready

$(document).ready() for the 21st century
JavaScript
334
star
7

refind-ambience

Minimal theme for the rEFInd boot manager
308
star
8

humanscript

A truly natural scripting language
Shell
224
star
9

htconvert

Convert .htaccess redirects to nginx.conf redirects
JavaScript
186
star
10

browser-env

Simulates a global browser environment using jsdom
JavaScript
171
star
11

coinlist

Comprehensive list of cryptocurrencies with metadata
JavaScript
155
star
12

coinflict-of-interest

Browser extension to show user biases on Crypto Twitter.
JavaScript
144
star
13

chest

Bash glue to encrypt and hide files
Shell
129
star
14

create-test-server

Creates a minimal Express server for testing
JavaScript
121
star
15

docker-electrumx

Run an Electrum server with one command
Dockerfile
101
star
16

base64-async

Non-blocking chunked Base64 encoding
JavaScript
98
star
17

doge-seed

Dank mnemonic seed phrases
HTML
86
star
18

onionite

Explore the Tor network
JavaScript
76
star
19

window

Exports a jsdom window object.
JavaScript
74
star
20

expired

Calculate when HTTP cache headers expire
JavaScript
74
star
21

github-custom-tab-size

Chrome extension - Set custom tab size for code view on GitHub.com
JavaScript
67
star
22

howmanyconfs.com

How many confirmations are equivalent to 6 Bitcoin confirmations?
JavaScript
60
star
23

create-cert

Super simple self signed certificates
JavaScript
43
star
24

react-jsdom

Render React components to actual DOM nodes in Node.js
JavaScript
33
star
25

byte-range

Returns integer ranges for C data types
JavaScript
32
star
26

parcel-plugin-ogimage

Set absolute URL for og:image meta tags.
JavaScript
22
star
27

build-output-script

Builds a P2PKH Bitcoin transaction output script
JavaScript
21
star
28

create-xpub

Create a BIP32 extended public key
JavaScript
21
star
29

onionoo-node-client

Node.js client library for the Tor Onionoo API
JavaScript
20
star
30

autoscale-do-block-storage

Autoscale Digital Ocean block storage volumes
Shell
20
star
31

my-name-is-url

Intelligent URL parser
JavaScript
17
star
32

docker-vertcoind

Run a full Vertcoin node with one command
Dockerfile
9
star
33

tippin-badge

Readme badge generator for tippin.me
HTML
8
star
34

docker-bitcoind

Run a full Bitcoin node with one command
Dockerfile
7
star
35

create-node

Converts an HTML string to a dom node
JavaScript
7
star
36

this

Traverses up the directory tree and returns the first module found
JavaScript
7
star
37

requirable

Enables a module to require itself by name
JavaScript
6
star
38

docker-ledger-sdk

Build a Ledger app with one command
Dockerfile
6
star
39

ephemeral-electrum

A quick throwaway text based Electrum instance.
Dockerfile
5
star
40

notary-node-utils

Utilities for running a notary node
Shell
5
star
41

electrs-next

Docker configuration for testing the `next` branch of electrs.
Dockerfile
4
star
42

docker-electrum-vertcoin

Run a Vertcoin Electrum server with one command
4
star
43

docker-barterdex-api

Shell
4
star
44

vainjs

A JavaScript vanity address generator
JavaScript
4
star
45

sign-release

Easy automated release signing
Shell
3
star
46

test

test repo for testing git/GitHub related things
1
star
47

vercel-bug

JavaScript
1
star
48

arrows

My custom ZSH theme
Shell
1
star
49

eslint-config-lukechilds

My personal eslint preferences
JavaScript
1
star
50

eslint-config-xo-lukechilds

My personal XO overrides
JavaScript
1
star
51

Extension

Browser extension to show user influence on Crypto Twitter.
JavaScript
1
star
52

morethan140

View and send tweets over 140 characters
JavaScript
1
star
53

pirateproxy

Proxy site for thepiratebay.org
JavaScript
1
star
54

b64golf

JavaScript
1
star
55

AtHash

Social text parser
JavaScript
1
star
56

javascript

How we like to JavasScript at Unsplash.
JavaScript
1
star
57

umbrel-apps-test-2

1
star
58

syringe

Search and inject packages from npm
JavaScript
1
star
59

blog-clj

Clojure
1
star
60

anonlytics-express

Privacy respecting analytics for express apps
JavaScript
1
star
61

tor-hs-issue-repro

Shell
1
star
62

trim

Rust
1
star
63

hyperdex-bugtracker

1
star
64

homebrew-tap

My Homebrew tap
Ruby
1
star
65

bip39-versioned

Proof of concept adding versioning to BIP39 compatible seeds
JavaScript
1
star