Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty .nvmrc file displays help text on sourcing #1113

Closed
jeffmikels opened this issue Jun 9, 2016 · 25 comments
Closed

Empty .nvmrc file displays help text on sourcing #1113

jeffmikels opened this issue Jun 9, 2016 · 25 comments
Labels
bugs Oh no, something's broken :-(
Milestone

Comments

@jeffmikels
Copy link

I have the following lines in my .bash_profile

export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"

nvm seems to be working fine, but I get the Node Version Manager help text displayed on my console on every login. It also happens whenever I execute . "$(brew --prefix nvm)/nvm.sh" from any command line. Clearly, after sourcing the file, the nvm function is getting called with no arguments. What is causing that?

I'm running bash on Mac OS X El Capitan.

@jeffmikels
Copy link
Author

I solved my problem by commenting out this line of code at the bottom of the nvm.sh script:

#nvm_process_parameters "$@"

I hope that doesn't break anything.

@ljharb
Copy link
Member

ljharb commented Jun 10, 2016

@jeffmikels nvm is completely unsupported on homebrew, which the brew formula warns you about when installing it.

So first, definitely do not make any edits to nvm.sh, as that will break some functionality. However, I highly brew uninstalling it, and installing it properly with the curl command in the readme.

@ljharb ljharb closed this as completed Jun 10, 2016
@ljharb ljharb added the non-issue / invalid This isn't relevant to nvm, or turned out to be something unrelated. label Jun 10, 2016
@jeffmikels
Copy link
Author

jeffmikels commented Jun 10, 2016

I removed the homebrew version of nvm.

I Installed it using the curl command.

I removed the lines from .bash_profile keeping the line from .bashrc

export NVM_DIR="/Volumes/Jeff/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

I STILL get the nvm --help text on every Terminal window.

I think this is undesirable and therefore a bug.

In the meantime, I have again commented out the nvm_process_parameters call.

@ljharb
Copy link
Member

ljharb commented Jun 10, 2016

@jeffmikels thanks for following up! would you be able to share the contents of .bashrc/.bash_profile that runs before the nvm lines?

@ljharb ljharb reopened this Jun 10, 2016
@ljharb ljharb removed the non-issue / invalid This isn't relevant to nvm, or turned out to be something unrelated. label Jun 10, 2016
@ljharb
Copy link
Member

ljharb commented Jun 10, 2016

Also, just to confirm - if you set your NVM_DIR to be $HOME/.nvm (the default) do you still see the same behavior?

@jeffmikels
Copy link
Author

jeffmikels commented Jun 10, 2016

To eliminate all bashrc and bash_profile problems, I can reproduce the problem using only sh.

sh -c "sh .nvm/nvm.sh"

or even better, a totally clean environment

env -i sh .nvm/nvm.sh

Both still display the nvm --help output.

@ljharb
Copy link
Member

ljharb commented Jun 10, 2016

Wow, that's super odd - the env -i should use the default NVM_DIR. However, is this .nvm directory still on /Volumes/Jeff instead of inside $HOME? It'd be ideal to test env -i on $HOME/.nvm/nvm.sh specifically

@jeffmikels
Copy link
Author

jeffmikels commented Jun 11, 2016

/Volumes/Jeff = $HOME

@ljharb
Copy link
Member

ljharb commented Jun 13, 2016

aha, i wonder if having $HOME be a volume, instead of a dir on the OS volume, could be causing issues. Can you clarify if you have a .nvmrc file anywhere (in whichever directory you run these commands in, or, in any directory upwards to /), and if so, what's in it?

@jeffmikels
Copy link
Author

jeffmikels commented Jun 14, 2016 via email

@ljharb
Copy link
Member

ljharb commented Jun 14, 2016

Thanks for working through it so far :-) My suspicion is having it on a separate volume. If you could share your bash profile file in a gist (with sensitive parts blotted out) that might help as well.

@jeffmikels
Copy link
Author

jeffmikels commented Jun 14, 2016

I moved the .bash_profile and the .bashrc out of my home directory entirely, opened a new terminal and the error persisted. Something in the script must be incompatible with my HOME setup.

When I log in without the .bash_profile or .bashrc, this is what my environment looks like:

TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-color
TMPDIR=/var/folders/gj/8bp694f15qb2zhl4q3l5ns700000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.B0l1jhHDO4/Render
TERM_PROGRAM_VERSION=361.1
TERM_SESSION_ID=1348E86F-150B-4D06-906C-7933E4BD5517
USER=jeff
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.nBlUQKJ1Zo/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/opt/ImageMagick/bin
PWD=/Volumes/Jeff
LANG=en_US.UTF-8
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Volumes/Jeff
LOGNAME=jeff
DISPLAY=/private/tmp/com.apple.launchd.5wvMIsQ6gY/org.macosforge.xquartz:0
SECURITYSESSIONID=186aa

@ljharb
Copy link
Member

ljharb commented Jun 14, 2016

Is /Volumes/Jeff case-sensitive, or case-insensitive?

@jeffmikels
Copy link
Author

jeffmikels commented Jun 14, 2016 via email

@jeffmikels
Copy link
Author

I have confirmed the following strange behavior:

cd /Volumes; . $HOME/.nvm/nvm.sh
cd /; . $HOME/.nvm/nvm.sh

No help text shown in either case.

cd /Volumes/Jeff; . $HOME/.nvm/nvm.sh

Help text IS shown.

The help text displays depending on the current working directory, and only seems to show when my current working directory is /Volumes/Jeff

@ljharb
Copy link
Member

ljharb commented Jun 14, 2016

Do you see the same behavior when you run nvm_auto use? What does nvm alias default report?

@jeffmikels
Copy link
Author

I DO get the same behavior with nvm_auto use.

nvm alias default reported nothing so I assigned it using nvm alias default 4.4.3 and now everything is FIXED!

The help text no longer shows up unless I want it to.

Why would that make a difference?

Before, I had these aliases set:

$ nvm alias

node -> stable (-> v4.4.3) (default)
stable -> 4.4 (-> v4.4.3) (default)
iojs -> N/A (default)

Now, I have these:

$ nvm alias

default -> 4.4.3 (-> v4.4.3)
node -> stable (-> v4.4.3) (default)
stable -> 4.4 (-> v4.4.3) (default)
iojs -> N/A (default)

@ljharb
Copy link
Member

ljharb commented Jun 14, 2016

OK - in that case, it's related to the automatic behavior of .nvmrc where nvm tries to crawl up the tree to / to locate config files - nvm_rc_version in that dir probably returns 0, but afterwards what does echo $NVM_RC_VERSION say?

@jeffmikels
Copy link
Author

Currently, echo $NVM_RC_VERSION yields nothing. Also, my .nvmrc file exists in $HOME but is empty.

@ljharb
Copy link
Member

ljharb commented Jun 14, 2016

ok that's the issue :-) the file is assumed to have contents if it's present.

I assume as well that if you nvm unalias default && rm "$HOME/.nvmrc" that everything works fine?

@jeffmikels
Copy link
Author

Yes, yes it does. If .nvmrc exists and is empty, I get the undesirable behavior. If .nvmrc does not exist, things work as they should. However, the script seems to only care if .nvmrc is in the current working directory because as noted before, when I was in a different directory, the help text would not show up.

Finally, I was under the assumption that nvm would handle configuration files the way other tools do, that is, settings in config files should override the existing defaults and configuration settings specified on the command line would get saved into the config file for future use. I touched the .nvmrc assuming that file needed to exist to make my settings persistent.

Is there documentation about the .nvmrc that I missed somewhere?

@jeffmikels
Copy link
Author

Found it... now I understand. .nvmrc is not a user level configuration file. It is a project level configuration file.

@ljharb
Copy link
Member

ljharb commented Jun 14, 2016

That's correct - although it's totally fine to use it at the user level, and I do so. It just can't be an empty file :-)

I'm going to reopen this to track fixing the issue though, an empty .nvmrc file should probably just be ignored.

@ljharb ljharb reopened this Jun 14, 2016
@ljharb ljharb changed the title How to disable display of help text when sourcing "$(brew --prefix nvm)/nvm.sh"? Empty .nvmrc file displays help text on sourcing Jun 14, 2016
@ljharb ljharb added the bugs Oh no, something's broken :-( label Jun 14, 2016
@jeffmikels
Copy link
Author

Thanks for working through this with me.

@ljharb
Copy link
Member

ljharb commented Jun 14, 2016

Thank you!!

@ljharb ljharb closed this as completed in 36b1ea9 Jun 14, 2016
@ljharb ljharb added this to the v0.31.2 milestone Jun 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugs Oh no, something's broken :-(
Projects
None yet
Development

No branches or pull requests

2 participants