Giter Site home page Giter Site logo

zsh-nvm's Introduction

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

zsh-nvm's People

Contributors

aitorciki avatar alexxnica avatar bibixx avatar eddiemonge avatar ethanwu10 avatar joerideg avatar lukechilds avatar lusoalex avatar riatre avatar sboekhoff avatar yads avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zsh-nvm's Issues

nvm upgrade doesn't work

Snipaste_2020-08-05_11-10-28
Snipaste_2020-08-05_11-10-53

It looks like nvm can't recogonize the upgrade child command.

My .zshrc:

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/yutengjing/.oh-my-zsh"

# Set name f the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="random"
ZSH_THEME="powerlevel10k/powerlevel10k"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
HIST_STAMPS="yyyy-mm-dd"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
# official
plugins=(
  alias-finder
  brew
  gem
  git
  npm
  pod
  sudo
  themes
  vscode
  yarn
  z
)
# unofficial
plugins+=(
  zsh-autosuggestions
  zsh-syntax-highlighting
  zsh-nvm
  zsh-better-npm-completion
  yarn-autocompletions
)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

# custom
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# proxy
proxy () {
  export http_proxy="http://127.0.0.1:7890"
  export https_proxy="http://127.0.0.1:7890"
  echo "HTTP Proxy on"
}

# close proxy
noproxy () {
  unset http_proxy
  unset https_proxy
  echo "HTTP Proxy off"
}

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

Can't upgrade nvm

Tracked the problem down to the _zsh_nvm_latest_release_tag function.
Command is

echo $(cd "$NVM_DIR" && git fetch --quiet origin && git describe --abbrev=0 --tags --match "v[0-9]*" origin)

Specifically:

git describe --abbrev=0 --tags --match "v[0-9]*" origin

is coming back as:

fatal: Not a valid object name origin

git ls-remote --tags origin lists the tags fine.

basename: missing operand

After installation using zplug, I'm getting this message on every new terminal

This is the output of zplug load:

$ zplug load 
Installing nvm...
Cloning into '/home/maturano/.nvm'...
remote: Counting objects: 5456, done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 5456 (delta 17), reused 0 (delta 0), pack-reused 5415
Receiving objects: 100% (5456/5456), 1.55 MiB | 556.00 KiB/s, done.
Resolving deltas: 100% (3290/3290), done.
Checking connectivity... done.
basename: missing operand
Try 'basename --help' for more information.

Env: zsh 5.0.2 (x86_64-pc-linux-gnu) on Ubuntu 14.04.5 LTS

_zsh_nvm_lazy_load:3: bad pattern: global_binaries=(bower

Seems to be an issue with the local array variables in my instance of oh-my-zsh on OSX. I fixed it by splitting declaration and assignment

local global_binaries
global_binaries=($(_zsh_nvm_global_binaries))

I can submit a PR for this, but I'm not sure if this is a localized issue.

zsh-nvm use not fully working

Able to change node versions in an open terminal.
Then opening a new tab or closing/opening terminal or switching panes in tmux reverts to initial node version?

↳ nvm ls
-> v10.15.2
v10.15.3

↳ nvm use 10.15.3
Now using node v10.15.3 (npm v6.4.1)

↳ nvm ls
v10.15.2
-> v10.15.3

Opened a new tab in terminal Or closed and opened terminal Or in tmux switched panes in same window and session:
↳ nvm ls
-> v10.15.2
v10.15.3

Ubuntu 18.04, zsh, omz, tmux

Error on lazy loading

Hello,

I have an error if i use lazy loading, here is what I get when opening a terminal:

/usr/bin/which: no bacon-love in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no create-react-app in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no electron in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no elementary-electron in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no functional-javascript in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no functional-javascript-workshop in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no oni in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no oni-vim in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no sccjs in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no scope-chains-closures in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no stream-adventure in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no yarn in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no yarnpkg in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)
/usr/bin/which: no nvm in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/home/martin/bin:/usr/local/sbin:/usr/sbin)

Do you have any idea of where it could come from?

Something wrong on your last commit

Hello;

I'm getting this error on your last commit.

home/ubuntu/.oh-my-zsh/tools/check_for_upgrade.sh: line 32: syntax error near unexpected token)'
/home/ubuntu/.oh-my-zsh/tools/check_for_upgrade.sh: line 32: () {' /home/ubuntu/.oh-my-zsh/oh-my-zsh.sh: line 21: autoload: command not found /home/ubuntu/.oh-my-zsh/oh-my-zsh.sh: line 39: syntax error near unexpected token ('
/home/ubuntu/.oh-my-zsh/oh-my-zsh.sh: line 39: for plugin ($plugins); do'

Issue with nvm upgrade

Hi,

I have been getting this error.

~/DEV
❯ nvm upgrade
Installed version is v0.33.8-4-g9273f23
Checking latest version of nvm...
Updating to v0.33.8...
error: pathspec '?]6;1;bg;red;brightness;157??]6;1;bg;green;brightness;194??]6;1;bg;blue;brightness;159?v0.33.8' did not match any file(s) known to git.
_zsh_nvm_upgrade:18: command not found: ^[]6;1;bg;red;brightness;157^G^[]6;1;bg;green;brightness;194^G^[]6;1;bg;blue;brightness;159^G

~/DEV
❯

My config is:

export NVM_LAZY_LOAD=true
zplug "lukechilds/zsh-nvm"
zplug "lukechilds/zsh-better-npm-completion", defer:2

Permission denied when trying to install the plugin

Trying to follow the installation instructions
https://github.com/lukechilds/zsh-nvm#as-an-oh-my-zsh-custom-plugin
and added to .zshrc:

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
plugins+=(zsh-nvm)
...
source $ZSH/oh-my-zsh.sh
...

but still getting the error

source .zshrc   
Installing nvm...
fatal: could not create leading directories of '/Users/dmitrizaitsev/.nvm': Permission denied
_zsh_nvm_install:cd:3: no such file or directory: /Users/dmitrizaitsev/.nvm

Any help?

Would be great to have ability to install zsh-nvm using homebrew

Homebrew is an essential package manager for developers, sysadmins, and power users on macOS.

Here is an example of other similar packages supported using homebrew.

Fatal error during `nvm upgrade`

I just discovered this plugin and decided to give it a go.
I seemed to have had nvm installed via homebrew, so uninstalled it.

I had had nvm 0.31.x installed, brew uninstalled it, and installed nvm fresh from nvm.sh, so I have 0.33.1installed now.

Whenever I run nvm upgrade I get the following output. This is the same output I have always gotten from the command regardless of nvm version, order of oh-my-zsh plugins, or whether it was installed from homebrew.

╰─➤  nvm upgrade
Installed version is v0.33.1
Checking latest version of nvm...
fatal: Not a valid object name origin
Updating to ...
warning: empty strings as pathspecs will be made invalid in upcoming releases. please use . instead if you meant to match all paths

Attempting to source nvm from within a ruby script does not use parent shell

Working with the nvm guys, we debugged a problem I'm having where attempting to use the zsh-nvm plugin causes a Rakefile that attempts to source the ~/.nvm/nvm.sh to use a different shell than the parent, or it sets some options that are incompatible or something. If I do not load the zsh-nvm plugin but I do source the nvm file myself then everything works as expected.

nvm-sh/nvm#1583

"command not found: CONTRIBUTING.md" on setup

Thanks for sharing & maintaining this tool!
I had a surprising error message on startup:

I install'd zsh-nvm with the manual process from https://github.com/lukechilds/zsh-nvm#manually

I got the following logs when I opened a new shell:

Installing nvm...
Cloning into '/Users/laurent/.nvm'...
remote: Counting objects: 6886, done.
remote: Total 6886 (delta 0), reused 0 (delta 0), pack-reused 6886
Receiving objects: 100% (6886/6886), 2.11 MiB | 656.00 KiB/s, done.
Resolving deltas: 100% (4312/4312), done.
error: pathspec 'CONTRIBUTING.md Dockerfile LICENSE.md Makefile README.md ROADMAP.md bash_completion install.sh nvm-exec nvm.sh package.json test update_test_mocks.sh v0.33.8' did not match any file(s) known to git.
_zsh_nvm_install:3: command not found: CONTRIBUTING.md

It's not critical: nvm seems to work, but I can't tell whether the setup is complete or not.

NVM does not load the default alias

Hello again,

I noticed that even though I have the "lag" at the shell start, the correct version of node is not loaded:

martin@yeti ~                                                                                              [15:06:34] 
> $ node --version                                                                                           ⬡ 6.9.5 
v6.9.5
martin@yeti ~                                                                                              [15:06:37] 
> $ nvm alias                                                                                                ⬡ 6.9.5 
default -> v7.5.0
node -> stable (-> v7.5.0) (default)
stable -> 7.5 (-> v7.5.0) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> N/A)
lts/argon -> v4.7.3 (-> N/A)
lts/boron -> v6.9.5 (-> N/A)

And the NVM_NO_USE is not set.

Installing via zplug

I am desperately trying to install NVM on ZSH and need some help please.
First I tried to make zplug work. Seems it works now.
I installed zsh-nvm and it looks like everything is fine:

zplug list --installed
lukechilds/zsh-nvm => none 

But it seems like either zsh-nvm nor nvm is working/installed?

zsh: command not found: zsh-nvm
zsh: command not found: nvm

Anything I am missing?

Thanks a lot!

`node:unset:1: no such hash table element: yarn`

I've installed using the manual install method (I'm on current head of master) and yarn with brew install yarn.

.zshrc:

export NVM_LAZY_LOAD=true
source ~/play/zsh-nvm/zsh-nvm.plugin.zsh

Everything works fine, but on each new shell, I get the following on the first invocation of node or any global module:

node
node:unset:1: no such hash table element: yarn
>

Lazy: Take precedence over preinstalled node

I installed yarn through brew instead of npm (as it's recommended that way), but since Yarn in brew depends on node, that gets installed as well, and using node or npm doesn't load nvm any more.

Binaries conflicting with existing commands creates error

Such as greenkeeper, which has the short form gk, which on my machine is aliased (gk: aliased to \gitk --all --branches).

I then get a warning when nvm loads gitk:unset:1: no such hash table element: gk.

$ nvm ls
nvm:unset:1: no such hash table element: gk
       v0.10.47
       v0.12.16
->       v6.8.1
default -> 6 (-> v6.8.1)
node -> stable (-> v6.8.1) (default)
stable -> 6.8 (-> v6.8.1) (default)
iojs -> N/A (default)
lts/* -> lts/argon (-> N/A)
lts/argon -> v4.6.0 (-> N/A)

Worse is trying to use gk makes it loop infinitely.

$ gk enable
gitk:unset:1: no such hash table element: gk
gitk:unset:1: no such hash table element: greenkeeper
gitk:unset:1: no such hash table element: ncu
gitk:unset:1: no such hash table element: node
gitk:unset:1: no such hash table element: npm
gitk:unset:1: no such hash table element: npm-check-updates
gitk:unset:1: no such hash table element: typings
gitk:unset:1: no such hash table element: yarn
gitk:unset:1: no such hash table element: yarnpkg
gitk:unset:1: no such hash table element: gk
gitk:unset:1: no such hash table element: greenkeeper
gitk:unset:1: no such hash table element: ncu
gitk:unset:1: no such hash table element: node
gitk:unset:1: no such hash table element: npm
gitk:unset:1: no such hash table element: npm-check-updates
gitk:unset:1: no such hash table element: typings
gitk:unset:1: no such hash table element: yarn
gitk:unset:1: no such hash table element: yarnpkg
gitk:unset:1: no such hash table element: gk
gitk:unset:1: no such hash table element: greenkeeper
gitk:unset:1: no such hash table element: ncu
gitk:unset:1: no such hash table element: node
gitk:unset:1: no such hash table element: npm
gitk:unset:1: no such hash table element: npm-check-updates
gitk:unset:1: no such hash table element: typings
gitk:unset:1: no such hash table element: yarn
gitk:unset:1: no such hash table element: yarnpkg
gitk:unset:1: no such hash table element: gk
gitk:unset:1: no such hash table element: greenkeeper
gitk:unset:1: no such hash table element: ncu
gitk:unset:1: no such hash table element: node
gitk:unset:1: no such hash table element: npm
gitk:unset:1: no such hash table element: npm-check-updates
gitk:unset:1: no such hash table element: typings
gitk:unset:1: no such hash table element: yarn
gitk:unset:1: no such hash table element: yarnpkg
gitk:unset:1: no such hash table element: gk
gitk:unset:1: no such hash table element: greenkeeper
gitk:unset:1: no such hash table element: ncu
gitk:unset:1: no such hash table element: node
gitk:unset:1: no such hash table element: npm
gitk:unset:1: no such hash table element: npm-check-updates
gitk:unset:1: no such hash table element: typings
gitk:unset:1: no such hash table element: yarn
gitk:unset:1: no such hash table element: yarnpkg

etc.

This is using LAZY, tbw.

Call the lazy load function inside a script

So, I have a couple of npm executables that are being used by my editor for linting & stuff. I'm trying to make this as dynamic as possible instead of me doing something like nvm use default before I open my editor, which most of the time I forget.

Also, these executables need to work from the local node_modules folder if exists otherwise fallback to the global one if available. So I'm trying to achieve this with the following bin scripts.

For eslint for example.

#!/usr/bin/env bash
$(npm-which eslint) $@

and the npm-which script looks like this

#!/usr/bin/env zsh

local npm_bin=$(npm bin) # <--- this is the problem
local bin_name=$1
local local_path="${npm_bin}/${bin_name}"

[[ -f $local_path ]] && echo $local_path && return
echo $(which $bin_name)

The problem is in the call to $(npm bin) this returns /usr/local/bin/npm & not the lazy loaded npm which is /Users/ahmed/.nvm/versions/node/v8.0.0/bin/npm

EDIT: So I removed that old npm install, but now the script returns an error instead

λ npm-which
npm not found
/Users/ahmed/.dotfiles/bin/npm-which:4: command not found: npm

So how can I make this work?

Adding custom commands that trigger lazy loading nvm/node

Hi,
First of all, thanks for your work on this plugin, its awesome.

I have the situation where my vim setup includes a plugin (coc and subplugins) that requires node to be available. Now if I enable NVM_LAZY_LOAD and start vim it would complain that node is not available. If I run 'node' before I start vim, node is of course available and there is no problem.

Would it be possible to add an option to configure additional commands that trigger the lazy load function? Maybe adding them to the global_binaries?

Unable to use "nvm upgrade" in oh-my-zsh

~ zsh --version
x86_64-apple-darwin18.2.0

Install zsh-nvm with oh-my-zsh:
git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm
# Add to ~/.zshrc:
plugins=(
  git
  zsh-nvm
)

source $ZSH/oh-my-zsh.sh

After restart terminal:

$ nvm upgrade    # output same as run nvm without any option/value

but
$ _zsh_nvm_upgrade # work

NVM_AUTO_USE :: Suppress output

When enabling NVM_AUTO_USE I am presented with the output of nvm use when I cd into a directory containing a .nvmrc file. Would be useful for a config option to suppress the output for those that already have shells setup to show the node version in the shell line.

Using starship:
image

Add Unit Tests

Add tests
Integrate with Travis, run on both osx and linux

Lazy load & auto use

I understand that this was mentioned in the README.md that we can't combine both, but I wonder if there is anything that can be done to make this work? I'd like to have both

Maybe when both are combined you just need to check if there is a .nvmrc file or not to load & use otherwise still be in lazy mode?

lazy loading causes delay on every command w/ spaceship-prompt theme

When I have NVM_LAZY_LOAD enabled I experience a several second delay after every command I run before the prompt returns. This appears to be caused by the spaceship prompt attempting to determine the current Node.js version when it detects a Node.js project in the current directory. I understand why lazy loading is triggered in this case, but I don’t get why it’s happening every time I run a command. Isn’t lazy loading only supposed to happen once per session?

NVM_AUTO_USE doesn't work with NVM_LAZY_LOAD until too late

_zsh_nvm_auto_use will return early if nvm_find_nvmrc is not found, which will be the case when lazy loading.

Would you consider including a copy of nvm_find_nvmrc inside your code if lazy loading, so that auto use can work as intended, before nvm, node, etc are run for the first time?

Lazy: Npm without other globals not available without loading nvm

I think this is the issue, not sure though...

I set this up on my work machine, and just nvm install 6.4 gives the following from which node in a new shell:

node () {
        unset -f node nvm
        _zsh_nvm_load
        node "$@"
}

Running npm i -g npm then a new session made no difference. I then installed npm-check-update and typings, which gave me:

node () {
        unset -f ncu node npm npm-check-updates typings nvm
        _zsh_nvm_load
        node "$@"
}

which npm gave me npm not found up until the last one.

Not sure why, but maybe it'll give you a starting point for where to look 😄

Antigen doesn't fully initialize

I ran antigen update recently. My themes stopped working. I bisected all my Antigen plugins. Everything works if I exclude zsh-nvm.

I did a git bisect on zsh-nvm, performing antigen reset in between checkouts. Looks like this started with 8bdba4f.

Problem installing the plugin when there is nvm already installed

I have a problem installing zsh-nvm via antigen

    λ ~ ◆ antigen bundle lukechilds/zsh-nvm
    .Cloning into '/Users/drinchev/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-lukechilds-SLASH-zsh-nvm.git'...
    remote: Counting objects: 228, done.
    remote: Compressing objects: 100% (47/47), done.
    remote: Total 228 (delta 16), reused 0 (delta 0), pack-reused 178
    Receiving objects: 100% (228/228), 29.54 KiB | 0 bytes/s, done.
    Resolving deltas: 100% (91/91), done.
    Checking connectivity... done.
    Installing nvm...
    fatal: destination path '/Users/drinchev/.nvm' already exists and is not an empty directory.
    fatal: Not a git repository (or any of the parent directories): .git
    fatal: Not a git repository (or any of the parent directories): .git
    λ ~ ◆ 

I already have nvm installed on my machine ( OS X El Capitan )

Additional information :

    λ ~ ◆ [[ ! -f "$NVM_DIR/nvm.sh" ]] && echo "nvm doesn't exist" || echo "nvm exists"
    nvm doesn't exist
    λ ~ ◆ echo $NVM_DIR
    /Users/drinchev/.nvm
    λ ~ ◆ ls -lah $NVM_DIR
    total 0
    drwxr-xr-x   5 drinchev staff  170 Oct 24  2015 .
    drwxr-xr-x+ 94 drinchev staff 3.2K Oct 18 23:23 ..
    drwxr-xr-x   3 drinchev staff  102 Oct 24  2015 alias
    drwxr-xr-x   4 drinchev staff  136 Sep 10 19:20 bin
    drwxr-xr-x   3 drinchev staff  102 Oct 24  2015 versions
    λ ~ ◆

Make sure lazy loading works with future updates to nvm

I've just added added lazy loading to zsh-nvm https://github.com/lukechilds/zsh-nvm#lazy-loading. I've tested and it all seems to be working well.

@ljharb I'm sure I remember reading an issue on nvm about lazy loading where someone had posted a method similar to this and you said that it would break with future changes you were planning to make to nvm regarding lts or something? Sorry, I've been searching but I can't find the exact issue now.

I've tried to be as generic as I can looking for binaries, checking everything in the versions folder not just node. I'm sure you're a very busy man but I'd really appreciate it if you could cast your eyes over this and give me a heads up if you think any changes you're gonna make to nvm will break this.

Juicy bits here:

_zsh_nvm_lazy_load() {
# Get all global node module binaries (including node)
local node_globals=($(ls "$NVM_DIR"/versions/*/*/bin/* | xargs basename | sort | uniq))
# Add nvm
node_globals+=('nvm')
# Create function for each command
for cmd in $node_globals; do
# When called, unset all lazy loaders, load nvm then run current command
eval "$cmd(){
unset -f $node_globals
_zsh_nvm_load
$cmd \"\$@\"
}"
done
}

No worries if you're too busy!

Does zsh-nvm support nvm options completion?

I love the plugin and appreciate the work you put in to make it possible.

Question

I'm not a filing a bug report but just asking a question or requesting a feature. Does zsh-nvm support options completion suggestions for nvm?

For example, with nvm install -- and then tab pressed I would expect the install options to be listed as suggestions:

--reinstall --lts ... etc.

Background

I am using OhMyZsh and have the plugin loaded along with the export of the bash profile as suggested in the README.

.zshrc. snippet:

# OhMyZsh stuff
...
export NVM_COMPLETION=true
plugins=(git zsh-nvm)
...
# Custom configurations

Does the export command above need to be in my .bashrc or .bash_profile instead of .zshrc? I was confused by the README about this:

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:

The above states to set NVM_COMPLETION in the .zshrc but it doesn't seem to do anything for me. Maybe the OMZ plugin just takes care of that by itself.

nvm is not compatible with the npm config prefix option currently set to ""

  • Arch linux
  • zsh 5.6.2 with zgen, tmux 2.8
  • nvm v0.34.0 (via zsh-nvm)
  • Deleted system nodejs and npm packages
  • deleted ~/.npmrc and removed nvm sourcing from ~/.zshrc since it's handled by zsh-nvm
  • Had issues with nvm for months so only used system node/npm until recently. Now that latest icu & http-parser libs used by other packages break node 10, I need to constantly downgrade/reupgrade the libs to switch between node 10 & 11, which is too much hassle, so I tried to come back to nvm and spent the morning trying to solve this nvm is not compatible with the npm config "prefix" option: currently set to "" error.
  • Deleted archlinux nvm package, installed zgen load lukechilds/zsh-nvm
$ PATH=".nvm/versions/node/v10.12.0/bin/:$PATH" node
[1]    27252 segmentation fault (core dumped) PATH=".nvm/versions/node/v10.12.0/bin/:$PATH" node  
$ /home/dori/.nvm/versions/node/v10.12.0/bin/node --version
v10.12.0
$ which node
/home/dori/.nvm/versions/node/v10.12.0/bin/node
$ nvm current
none
$ nvm ls
       v10.12.0
default -> v10.12 (-> v10.12.0)
node -> stable (-> v10.12.0) (default)
stable -> 10.12 (-> v10.12.0)

$ nvm use v10.12
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v10.12.0` to unset it.
$ which node
node not found
$ nvm use --delete-prefix v10.12.0
$ which node
/home/dori/.nvm/versions/node/v10.12.0/bin/node
$ node --version
v10.12.0
$ node --help
[1]    19251 segmentation fault (core dumped)  node --help
$ /home/dori/.nvm/versions/node/v10.12.0/bin/node --help                                                    
Usage: node [options] [ -e script | script.js | - ] [arguments]                                             
       node inspect script.js [arguments]                                                                   
                                                                                                            
Options: 

$ npm --version
[1]    28966 segmentation fault (core dumped)  npm --version
$ which npm
/home/dori/.nvm/versions/node/v10.12.0/bin/npm
$  /home/dori/.nvm/versions/node/v10.12.0/bin/npm --version
[1]    5939 segmentation fault (core dumped)  /home/dori/.nvm/versions/node/v10.12.0/bin/npm --version
$ ls -lh  ~/.nvm/versions/node/v10.12.0/bin
total 38M
-rwxr-xr-x 1 dori dori 38M Oct 11 04:53 node
lrwxrwxrwx 1 dori dori  38 Oct 11 04:54 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 dori dori  38 Oct 11 04:54 npx -> ../lib/node_modules/npm/bin/npx-cli.js
$ ls -lh  ~/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm
-rwxr-xr-x 1 dori dori 833 Aug  3 01:58 /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm
$ vim /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm # set echo
/home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm --version                             
NODE: node; NPM_CLI_JS: /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js; @: --version
/home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm: line 35: 31882 Segmentation fault      (core dumped) "$NODE_EXE" "$NPM_CLI_JS" "$@"
$ ls /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js
ls: cannot access '/home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js': No such file or directory
$ ls /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm-cli.js
/home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm-cli.js

From this, I understand that NPM_CLI_JS has a duplicated node_modules/npm/bin/ in its path

$ sed -i "s/node_modules\/npm\/bin\///g" /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm
$ /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm --version
NODE: node; NPM_CLI_JS: /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm-cli.js; @: --version
/home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm: line 35: 20130 Segmentation fault      (core dumped) "$NODE_EXE" "$NPM_CLI_JS" "$@"
$ /home/dori/.nvm/versions/node/v10.12.0/bin/node /home/dori/.nvm/versions/node/v10.12.0/lib/node_modules/npm/bin/npm-cli.js --version
6.4.1
$ /home/dori/.nvm/versions/node/v10.12.0/bin/npm --version
[1]    5939 segmentation fault (core dumped)  /home/dori/.nvm/versions/node/v10.12.0/bin/npm --version
$ /usr/bin/env node
[1]    21184 segmentation fault (core dumped)  /usr/bin/env node
/usr/bin/env npm 
[1]    21654 segmentation fault (core dumped)  /usr/bin/env npm

So, the problem is with /usr/bin/env ? I don't know how to debug this further :(

more details
$ nvm debug
nvm --version: v0.34.0
$SHELL: /bin/zsh
$SHLVL: 4
$HOME: /home/dori
$NVM_DIR: '$HOME/.nvm'
$PATH: $NVM_DIR/versions/node/v10.12.0/bin:$HOME/.rvm/gems/ruby-2.5.1/bin:$HOME/.rvm/gems/ruby-2.5.1@global/bin:$HOME/.rvm/rubies/ruby-2.5.1/bin:/opt/google-cloud-sdk/bin:./vendor/bin:node_modules/.bin:$HOME/.pub-cache/bin:$HOME/Projects/personal/flutter/flutter/bin:/opt/genymotion/tools/:$HOME/.cargo/bin:/usr/lib/jvm/java-8-openjdk/jre/bin/:/opt/android-sdk/tools/bin:/opt/android-sdk/emulator:$HOME/.gem/ruby/2.5.0/bin:$HOME/bin:/opt/google-cloud-sdk/bin:./vendor/bin:node_modules/.bin:$HOME/.pub-cache/bin:$HOME/Projects/personal/flutter/flutter/bin:/opt/genymotion/tools/:$HOME/.cargo/bin:/usr/lib/jvm/java-8-openjdk/jre/bin/:/opt/android-sdk/tools/bin:/opt/android-sdk/emulator:$HOME/.gem/ruby/2.5.0/bin:$HOME/bin:$HOME/.rvm/gems/ruby-2.5.1/bin:$HOME/.rvm/gems/ruby-2.5.1@global/bin:$HOME/.rvm/rubies/ruby-2.5.1/bin:/opt/google-cloud-sdk/bin:./vendor/bin:node_modules/.bin:$HOME/.pub-cache/bin:$HOME/Projects/personal/flutter/flutter/bin:/opt/genymotion/tools/:$HOME/.cargo/bin:/usr/lib/jvm/java-8-openjdk/jre/bin/:/opt/android-sdk/tools/bin:/opt/android-sdk/emulator:$HOME/.gem/ruby/2.6.0/bin:$HOME/bin:/opt/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/anaconda/bin/:$HOME/.fzf/bin:$HOME/Projects/3rdpart/phalcon-devtools:$HOME/.rvm/bin:/opt/anaconda/bin/:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/anaconda/bin/:$HOME/Projects/3rdpart/phalcon-devtools              
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.6.2 (x86_64-pc-linux-gnu)'
uname -a: 'Linux 4.20.1-arch1-1-ARCH #1 SMP PREEMPT Wed Jan 9 20:25:43 UTC 2019 x86_64 GNU/Linux'           
OS version: Arch Linux  ()
curl: /usr/bin/curl, curl 7.63.0 (x86_64-pc-linux-gnu) libcurl/7.63.0 OpenSSL/1.1.1a zlib/1.2.11 libidn2/2.1.0 libpsl/0.20.2 (+libidn2/2.1.0) libssh2/1.8.0 nghttp2/1.35.1
wget: /usr/bin/wget, GNU Wget 1.20.1 built on linux-gnu.
git: /usr/bin/git, git version 2.20.1
grep: grep: aliased to grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}), grep (GNU grep) 3.3
awk: /usr/bin/awk, GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)
sed: /usr/bin/sed, sed (GNU sed) 4.7
cut: /usr/bin/cut, cut (GNU coreutils) 8.30
basename: /usr/bin/basename, basename (GNU coreutils) 8.30
rm: /usr/bin/rm, rm (GNU coreutils) 8.30
mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.30
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.6.0
nvm current: none
which node: $NVM_DIR/versions/node/v10.12.0/bin/node
which iojs: iojs not found
which npm: $NVM_DIR/versions/node/v10.12.0/bin/npm
npm config get prefix: 
npm root -g: 

$ nvm deactivate
/home/dori/.nvm/*/bin removed from $PATH

$ nvm debug
nvm --version: v0.34.0
$SHELL: /bin/zsh
$SHLVL: 4
$HOME: /home/dori
$NVM_DIR: '$HOME/.nvm'
$PATH: $HOME/.rvm/gems/ruby-2.5.1/bin:$HOME/.rvm/gems/ruby-2.5.1@global/bin:$HOME/.rvm/rubies/ruby-2.5.1/bin:/opt/google-cloud-sdk/bin:./vendor/bin:node_modules/.bin:$HOME/.pub-cache/bin:$HOME/Projects/personal/flutter/flutter/bin:/opt/genymotion/tools/:$HOME/.cargo/bin:/usr/lib/jvm/java-8-openjdk/jre/bin/:/opt/android-sdk/tools/bin:/opt/android-sdk/emulator:$HOME/.gem/ruby/2.5.0/bin:$HOME/bin:/opt/google-cloud-sdk/bin:./vendor/bin:node_modules/.bin:$HOME/.pub-cache/bin:$HOME/Projects/personal/flutter/flutter/bin:/opt/genymotion/tools/:$HOME/.cargo/bin:/usr/lib/jvm/java-8-openjdk/jre/bin/:/opt/android-sdk/tools/bin:/opt/android-sdk/emulator:$HOME/.gem/ruby/2.5.0/bin:$HOME/bin:$HOME/.rvm/gems/ruby-2.5.1/bin:$HOME/.rvm/gems/ruby-2.5.1@global/bin:$HOME/.rvm/rubies/ruby-2.5.1/bin:/opt/google-cloud-sdk/bin:./vendor/bin:node_modules/.bin:$HOME/.pub-cache/bin:$HOME/Projects/personal/flutter/flutter/bin:/opt/genymotion/tools/:$HOME/.cargo/bin:/usr/lib/jvm/java-8-openjdk/jre/bin/:/opt/android-sdk/tools/bin:/opt/android-sdk/emulator:$HOME/.gem/ruby/2.6.0/bin:$HOME/bin:/opt/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/anaconda/bin/:$HOME/.fzf/bin:$HOME/Projects/3rdpart/phalcon-devtools:$HOME/.rvm/bin:/opt/anaconda/bin/:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/anaconda/bin/:$HOME/Projects/3rdpart/phalcon-devtools                                                                                                   
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.6.2 (x86_64-pc-linux-gnu)'
uname -a: 'Linux 4.20.1-arch1-1-ARCH #1 SMP PREEMPT Wed Jan 9 20:25:43 UTC 2019 x86_64 GNU/Linux'
OS version: Arch Linux  ()
curl: /usr/bin/curl, curl 7.63.0 (x86_64-pc-linux-gnu) libcurl/7.63.0 OpenSSL/1.1.1a zlib/1.2.11 libidn2/2.1.0 libpsl/0.20.2 (+libidn2/2.1.0) libssh2/1.8.0 nghttp2/1.35.1                                                      
wget: /usr/bin/wget, GNU Wget 1.20.1 built on linux-gnu.
git: /usr/bin/git, git version 2.20.1
grep: grep: aliased to grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}), grep (GNU grep) 3.3                                                                
awk: /usr/bin/awk, GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)
sed: /usr/bin/sed, sed (GNU sed) 4.7
cut: /usr/bin/cut, cut (GNU coreutils) 8.30
basename: /usr/bin/basename, basename (GNU coreutils) 8.30
rm: /usr/bin/rm, rm (GNU coreutils) 8.30
mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.30
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.6.0
nvm current: none
which node: node not found
which iojs: iojs not found
which npm: npm not found
npm config get prefix: npm may be found in the following packages:
  community/npm
  6.1.0-1
  /usr/bin/npm
  community/npm
  6.1.0-1
  /usr/lib/node_modules/npm/bin/npm
npm root -g: npm may be found in the following packages:
  community/npm
  6.1.0-1
  /usr/bin/npm
  community/npm
  6.1.0-1
  /usr/lib/node_modules/npm/bin/npm

$ echo $PREFIX ; echo $NPM_CONFIG_PREFIX


$ setopt
alwaystoend
autocd
autopushd
noclobber
completeinword
extendedglob
extendedhistory
noflowcontrol
histexpiredupsfirst
histignoredups
histignorespace
histverify
incappendhistory
interactive
interactivecomments
kshglob
login
longlistjobs
monitor
promptsubst
pushdignoredups
pushdminus
sharehistory
shinstdin
zle

Related issues:

nvm dont use default version in new terminals - VScode terminal

Hi!
I don't understand too well the zshrc config file, or PATH settings, so be patient with me :)
I just want to know why VScode dont use default version in new terminals

I use WSL2 on Windows, and its extension for VScode

I checked a lot of solutions, including:

  • node version installed before nvm -> no
  • i tried nvm alias default stable and nvm alias default node, and it really updates my nvm, but dont change the version in new sessions
  • i tried nvm deactivate

After that, I realized that my "Windows Terminal" (the new one) remembers the default node version in my WSL distro, but my VScode terminal dont
How is that possible?

Can anyone help me with this?
I dont really even know how to start looking for this problem..

(sry my bad english)

nvm load on session start takes ~30 seconds, lazy load not working

Hi everybody,

I have had this problem for some time now and didn't find a solution, so I hope you guys can help me out.
When I use zsh-nvm without lazy load, the session start takes insanely long (~30 seconds).
That startup is only that slow when I open Terminal the first time after a restart of the machine.
When I use lazy loading, .nvmrc files are ignored until I manually enter something like nvm -v and then cd in the corresponding folder.

EDIT:
I just saw that you wrote about this in the README: https://github.com/lukechilds/zsh-nvm#auto-use

I tried to fix it according to issue #28 but adding PATH before zsh-nvm didn't change anything.

add-zsh-hook chpwd _zsh_nvm_auto_use && echo yep || echo nope

gives me yep

I don't know what I should look for or what the culprit could be.
I hope you guys can give me some tips on where to look!

Installing nightly changed the stable alias??

nvm  list
         v8.6.0
         v9.2.0
-> v10.0.0-nightly20171121a95d88c881
default -> node (-> v10.0.0-nightly20171121a95d88c881)
nightly -> v10.0.0-nightly20171121a95d88c881
node -> stable (-> v10.0.0-nightly20171121a95d88c881) (default)
stable -> 10.0 (-> v10.0.0-nightly20171121a95d88c881) (default)

Is this expected behavior, doesn't seem like it.

install error with zgen

When attempting to install with zgen I get:
Creating a zgen save
/home/chester/.zgen/lukechilds/zsh-nvm-master/zsh-nvm.plugin.zsh:65: parse error near ]]'``

Unable to install nightly

$ nvm install nightly         
Version 'node' not found - try `nvm ls-remote` to browse available versions.
Clearing mirror cache...
Done!

Let me know if you need any more information.

NVM_LAZY_LOAD not decreasing load time

I'm trying to use NVM_LAZY_LOAD to decrease the load time of my shell but it doesn't seem to have any effect.

This is my .antigenrc file

Load the oh-my-zsh's library.

antigen use oh-my-zsh

# Bundles from the default repo (robbyrussell's oh-my-zsh).
antigen bundle git
antigen bundle github
antigen bundle brew
antigen bundle nvm
antigen bundle command-not-found
antigen bundle fzf
antigen bundle docker-compose

# zsh-users bundles
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-completions
antigen bundle zsh-users/zsh-history-substring-search

# Custom bundles
export NVM_LAZY_LOAD=true
antigen bundle lukechilds/zsh-nvm

# Load the theme.
antigen theme robbyrussell

# Tell Antigen that you're done.
antigen apply

I run the following command to time my shell:

for i in $(seq 1 4); do /usr/bin/time $SHELL -i -c exit; done

Results without NVM_LAZY_LOAD:
5.25 real 2.19 user 2.40 sys
4.15 real 1.94 user 2.06 sys
3.75 real 1.86 user 1.85 sys
3.73 real 1.85 user 1.85 sys

Result with lazy loading:
4.18 real 1.94 user 1.98 sys
3.66 real 1.83 user 1.81 sys
3.65 real 1.81 user 1.81 sys
3.59 real 1.78 user 1.78 sys

Auto use should be called once initially

When I open a terminal directly into my project directory, the auto use feature doesn't work, because the "working directory changed" hook never runs.

This makes the plugin almost useless when using terminals inside of VSCode, since all terminals are opened directly into the project directory. I have to "cd ..; cd -" to activate the right NodeJS version. At that point I might as well just activate it manually.

This should be fixed by running the auto use function once when the plugin is initialized.

nvm completion not loading properly

When using this plugin (installed using antigen), and setting export NVM_COMPLETION=true, I don’t get proper completion when I type nvm <tab>. I get path based completion suggestions instead.

Zsh version: zsh 5.8 (x86_64-apple-darwin21.0)
MacOS version: 12.0.1
Macbook M1 Pro

I dug around in the code, and found that when I run the _zsh_nvm_completion function manually from my prompt, completion works fine (click to watch below recording). What is weird is when I edited the file to check that function was running, and sourcing $NVM_DIR/bash_completion successfully, I could see that it was.

  [[ -r $NVM_DIR/bash_completion ]] && source $NVM_DIR/bash_completion && echo "Successfully sourced bash completion"

asciicast

I took a look at $NVM_DIR/bash_completion to see what I could make out, and used set -x to get some debug. I can see that calling the function manually after opening a new shell seems to do a lot more. I’m not familiar enough with completion to understand where it’s going wrong. I can’t follow the complete:13 debug to see why nothing else runs. The call to complete on the last line of $NVM_DIR/bash_completion completes without error.

Here is the debug from opening a new shell:

+/Users/Mark.Crossfield/.nvm/bash_completion:6> command -v nvm
+/Users/Mark.Crossfield/.nvm/bash_completion:87> [[ -n 5.8 ]]
+/Users/Mark.Crossfield/.nvm/bash_completion:90> command -v compinit
+/Users/Mark.Crossfield/.nvm/bash_completion:97> autoload -U +X bashcompinit
+/Users/Mark.Crossfield/.nvm/bash_completion:97> bashcompinit
+bashcompinit:177> unfunction bashcompinit
+bashcompinit:178> autoload -Uz bashcompinit
+bashcompinit:179> return 0
+/Users/Mark.Crossfield/.nvm/bash_completion:100> complete -o default -F __nvm nvm
+complete:1> emulate -L zsh
+complete:2> local args void cmd print remove
+complete:3> args=( -o default -F __nvm nvm ) 
+complete:4> zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v 'p=print' 'r=remove'
+complete:6> [[ -n '' ]]
+complete:8> [[ -n '' ]]
+complete:13> compdef '_bash_complete -o default -F __nvm' nvm

And here’s the debug from calling the _zsh_nvm_completion function for comparison:

+/Users/Mark.Crossfield/.nvm/bash_completion:6> command -v nvm
+/Users/Mark.Crossfield/.nvm/bash_completion:87> [[ -n 5.8 ]]
+/Users/Mark.Crossfield/.nvm/bash_completion:90> command -v compinit
+/Users/Mark.Crossfield/.nvm/bash_completion:97> autoload -U +X bashcompinit
+/Users/Mark.Crossfield/.nvm/bash_completion:97> bashcompinit
+bashcompinit:177> unfunction bashcompinit
+bashcompinit:178> autoload -Uz bashcompinit
+bashcompinit:179> return 0
+/Users/Mark.Crossfield/.nvm/bash_completion:100> complete -o default -F __nvm nvm
+complete:1> emulate -L zsh
+complete:2> local args void cmd print remove
+complete:3> args=( -o default -F __nvm nvm ) 
+complete:4> zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v 'p=print' 'r=remove'
+complete:6> [[ -n '' ]]
+complete:8> [[ -n '' ]]
+complete:13> compdef '_bash_complete -o default -F __nvm' nvm
+compdef:1> local opt autol type func delete eval new i ret=0 cmd svc
+compdef:2> local -a match mbegin mend
+compdef:4> emulate -L zsh
+compdef:5> setopt extendedglob
+compdef:9> ((  ! 2  ))
+compdef:14> getopts anpPkKde opt
+compdef:38> shift OPTIND-1
+compdef:40> ((  ! 2  ))
+compdef:45> [[ -z '' ]]
+compdef:49> [[ -z '' ]]
+compdef:49> [[ '_bash_complete -o default -F __nvm' = *=* ]]
+compdef:79> func='_bash_complete -o default -F __nvm' 
+compdef:80> [[ -n '' ]]
+compdef:81> shift
+compdef:83> case  (widgetkey)
+compdef:83> case  (key)
+compdef:83> case  (*)
+compdef:131> ((  1  ))
+compdef:132> [[ nvm = -N ]]
+compdef:134> [[ nvm = -p ]]
+compdef:136> [[ nvm = -P ]]
+compdef:139> case  (pattern)
+compdef:139> case  (postpattern)
+compdef:139> case  (*)
+compdef:155> [[ nvm = *=* ]]
+compdef:159> cmd=nvm 
+compdef:160> svc='' 
+compdef:162> [[ -z '' ]]
+compdef:163> _comps[$cmd]='_bash_complete -o default -F __nvm' 
+compdef:164> [[ -n '' ]]
+compdef:169> shift
+compdef:131> ((  0  ))

Make npm prefix working

I have the following npm configuration to make it conform with the XDG basedir specification:

prefix=${XDG_DATA_HOME}/npm
cache=${XDG_CACHE_HOME}/npm
tmp=${XDG_RUNTIME_DIR}/npm
init-module=${XDG_CONFIG_HOME}/npm/config/npm-init.js

I set the $NPM_CONFIG_USERCONFIG environment variable to $XDG_CONFIG_HOME/npm/npmrc to load the above content. Furthermore I set $NVM_DIR to $XDG_DATA_HOME/nvm.

I get some errors for nvm use (enabled $NVM_AUTO_USE). I think the reason becomes clear when I call nvm install v12. Which brings the following output:

v12.16.3 is already installed.
nvm is not compatible with the npm config "prefix" option: currently set to "/home/thore/.local/share/npm"
Run `npm config delete prefix` or `nvm use --delete-prefix v12.16.3` to unset it.

I'm not sure what the suggested solutions do in detail. I really want to keep my documentation. Is this possible?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.