lukechilds / zsh-nvm

Zsh plugin for installing, updating and loading nvm
MIT License
2.24k stars 113 forks source link

basename: missing operand #8

Closed maturanomx closed 8 years ago

maturanomx commented 8 years ago

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

lukechilds commented 8 years ago

Thanks for reporting πŸ‘

Looking into it now.

lukechilds commented 8 years ago

@maturano Do you have lazy loading enabled?

export NVM_LAZY_LOAD=true
maturanomx commented 8 years ago

@lukechilds Yes I do :)

lukechilds commented 8 years ago

Sweet, almost got a fix πŸ‘

Btw, was it just:

basename: missing operand
Try 'basename --help' for more information.

that you are getting on every new terminal or are you getting the Installing nvm..

lukechilds commented 8 years ago

@maturano The issue was caused by the lazy loading code. I grab a list of all the global modules and then format them into an ordered array of unique basenames. I wasn't checking if I actually had any items in the list before trying to run basename so if you didn't have any globals (no versions of node after a fresh install) it would run basename against an empty string, hence the basename: missing operand error.

I'm checking if we have any globals before trying to format them now: https://github.com/lukechilds/zsh-nvm/commit/007fd93fd71d6bcb12a0a688f47c9e9f58fdbaff

If you run zplug update you should be golden πŸŽ‰

lukechilds commented 8 years ago

@maturano Let me know if thats resolved it so I can close the issue πŸ‘

maturanomx commented 8 years ago

First, I had not installed any node version and I was just getting

basename: missing operand
Try 'basename --help' for more information.

Now, I update the plugin:

$ zplug update
Updated!             lukechilds/zsh-nvm     (3.55s)

open a new terminal and I get this:

basename: extra operand β€˜/home/maturano/.nvm/versions/node/v4.5.0/bin/node’
Try 'basename --help' for more information.

But, as you can deduce, I installed node 4.5.0 with nvm. Let me do a fresh install :)

maturanomx commented 8 years ago

Clean install:

After nvm install --lts node, in new terminal:

_zsh_nvm_global_binaries:local:3: not valid in this context: /home/maturano/.nvm/versions/node/v4.5.0/bin/npm
lukechilds commented 8 years ago

Hmmn, looks like it was caused by missing quotes: https://github.com/lukechilds/zsh-nvm/commit/ce7bc2a0a2d6439a0e3a9ab38309a527d74ade60

Can you try again after another zplug update.

Weird though, it works without the quotes on my MacBook. Might be a zsh version thing, I'm on 5.2. Getting the same issue as you on an Ubuntu VM with zsh 5.0.2.

maturanomx commented 8 years ago

After update: no message, but LAZY_LOAD stop working: always load node :)

lukechilds commented 8 years ago

What do you mean by not working?

lukechilds commented 8 years ago

If lazy loading is working properly it should appear as though node is loaded. It's not actually loaded it's just a shell function called "node" that will load nvm and then run node when called.

You can check if it's working properly by running the following straight after starting a new session:

vagrant-ubuntu-trusty-64% type node
node is a shell function
vagrant-ubuntu-trusty-64% node --version
v4.5.0
vagrant-ubuntu-trusty-64% type node
node is /home/vagrant/.nvm/versions/node/v4.5.0/bin/node
maturanomx commented 8 years ago

With .zshrc like:

NVM_LAZY_LOAD=true

zplug "johnhamelink/rvm-zsh"

Opening new terminal on commit 007fd93 :

_zsh_nvm_global_binaries:local:3: not valid in this context: /home/maturano/.nvm/versions/node/v4.5.0/bin/npm
 ~ $ node --version
zsh: command not found: node

Opening new terminal on commit ce7bc2a0a2d6439a0e3a9ab38309a527d74ade60 :

# (Clean, no message)
$ node --version
v4.5.0

I hope explain better now :smile:

lukechilds commented 8 years ago

That looks like it's working πŸ‘

Start a new session and run this to check:

type node && node --version && type node

If it's working you should get:

vagrant-ubuntu-trusty-64% type node && node --version && type node
node is a shell function
v4.5.0
node is /home/vagrant/.nvm/versions/node/v4.5.0/bin/node
maturanomx commented 8 years ago

I'm getting the same output but, let me give more context:

I don't use node all the time, that's why I also have the autoenv plugin to load node (and/or others virtual enviroments) just when I needed. I use the powerlevel9k theme to display my enviroment.

On commit 007fd93 this is what I get: screenshot_2016-09-27_165514_564x364

I don't have node, my enviroment is clean.

With the las commit ( ce7bc2a ), this is what I get: screenshot_2016-09-27_165630_564x364

Apparently, load node automatically :confused: ... That's what I tried to avoid with the NVM_LAZY_LOAD option.

lukechilds commented 8 years ago

Ah I see. As of commit https://github.com/lukechilds/zsh-nvm/commit/ce7bc2a0a2d6439a0e3a9ab38309a527d74ade60 everything is working correctly. Lazy loading is working properly, that's why the first time you run type node you get node is a shell function. This means node is not loaded.

Lazy loading works by creating shell functions for all of your node globals. Node isn't loaded. Then when one of those shell functions is called, nvm is loaded along with node and the global you tried to run is executed.

I would guess that your theme is checking if node is enabled by running node --version and if it gets output, showing the output as the currently loaded node version. With lazy loading enabled node won't be loaded until you run node. Running node --version will then cause node to be loaded.

Your theme is probably doing this in a sub process so node is loaded in the sub process and not in your main process. That's why the lazy load test command I gave you says node isn't loaded at first but your theme thinks it is.

So to clarify, lazy loading is now working as expected. The issue with your theme is completely unrelated.

lukechilds commented 8 years ago

Just checked the theme, it is indeed checking the node version in a sub process: https://github.com/bhilburn/powerlevel9k/blob/c4fdc8f70804fea6f543e6bbf3964301e2537e36/powerlevel9k.zsh-theme#L615-L621

I'm going to close this issue now because the original problem is resolved (thanks for your help debugging).

Feel free to open a new issue about compatibility issues between zsh-nvm and powerlevel9k. It should be pretty easy to fix with a PR to powerlevel9k.

lukechilds commented 8 years ago

@maturano I've just created this issue: https://github.com/lukechilds/zsh-nvm/issues/9

This will allow nvm to work how you want, meaning no node versions are loaded until you explicitly load them. Should be pretty easy to implement, hoping to have it done in the next couple of days.

maturanomx commented 8 years ago

That will be excellent @lukechilds !!! :smiley: