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

Add nvm current command #111

Closed
IlanCosman opened this issue Jul 19, 2020 · 12 comments
Closed

Add nvm current command #111

IlanCosman opened this issue Jul 19, 2020 · 12 comments

Comments

@IlanCosman
Copy link

I think an nvm current command would be useful for symmetry with the original nvm and most other fish nvm addons. This would make it simpler for a bash/zsh user to switch to fish and be greeted with the same commands.

@jorgebucaran
Copy link
Owner

@IlanCosman What would nvm current do?

@IlanCosman
Copy link
Author

IlanCosman commented Jul 20, 2020

I would expect it to operate similarly to the "real" nvm current. That is: display the currently activated version of Node, aliasing the system version to system.

In particular I'm requesting this for theming purposes.

Most of the other fish nvm addons are merely wrappers around nvm, and therefore use nvm current. Thus, bobthefish uses nvm current to see if the current node version is not the system one. Obviously this method fails without an nvm current command, so your plugin will not play nicely with bobthefish.

Tide similarly plans to use the nvm current method as it has wide support among the plugins, though your project does have the most stars.

It seems beneficial to this project and the users of these fish themes to add an nvm current command.

@jorgebucaran
Copy link
Owner

@IlanCosman It seems beneficial to this project and the users of these fish themes to add an nvm current command.

How's nvm current different from node -v?

@ljharb
Copy link

ljharb commented Jul 20, 2020

In particular, it returns system if it's not a managed version.

@jorgebucaran
Copy link
Owner

jorgebucaran commented Jul 20, 2020

Sorry, but I don't understand how this is useful. What does Tide plan to do with this, and why not node -v?

@IlanCosman
Copy link
Author

IlanCosman commented Jul 20, 2020

Tide (and bobthefish) want to display the node version if and only if it's not the system's default version, i.e it's being messed with by nvm. I don't know how nvm current does it, but it knows what the system version is. Thus by checking nvm current Tide and bobthefish can know when nvm is in use and display the node version to the user.

node -v tells us the version, but we don't know if that's the system's native version or an nvm managed one.

@jorgebucaran
Copy link
Owner

Tide (and bobthefish) want to display the node version if and only if it's not the system's default version

Hmm, got it! Okay, so, in fish-nvm, there's really no way to go back to the system node other than by uninstalling fish-nvm, so nvm current here could only return system if you just installed fish-nvm and haven't used it yet.

FWIW, fish-nvm saves the current version in ~/.config/nvm/version, so checking if that file exists or not is a way to know if you've already used nvm at least once.

@IlanCosman
Copy link
Author

Hmm, perhaps fish-nvm could store the node version at the time of install as system_node_version? Then the nvm current command could simply be node --version with a little extra bit replacing system_node_version's value with system.

@jorgebucaran
Copy link
Owner

jorgebucaran commented Jul 25, 2020

IlanCosman/tide#10 (comment)

@IlanCosman The system node version is the normal expected thing, and if the user is using a different one we can likely infer that they are working on a node project for which they need a different version.

I'd just show the Node version, whatever it is. Managed or not makes no difference to me because switching to a particular version of Node with fish-nvm makes it immediately available and shared between all the current user's fish instances, and will be preserved across restarts of the shell as well.

I never used the original nvm, but I suspect it doesn't work like that. @ljharb or anyone else is welcome to correct me.


Referring "to system node" in my previous comment was a bit misleading. There's usually no system node unless you happen to have node installed already, e.g., you compiled/downloaded it yourself, and that's never been my use case, since I use fish-nvm to get node in the first place.

Even if we add an nvm current command, it would be exactly the same as node -v. Let's leave the issue open for now.

@IlanCosman
Copy link
Author

Sounds good, thanks for your attention on this :)

@ljharb
Copy link

ljharb commented Jul 25, 2020

In nvm, nvm displays system when node isn't an nvm-managed version, and never displays the actual system version anywhere (node -v, of course, shows it).

If you want to know the current node version, node -v already exists - there's no value imo in just wrapping node -v :-) iow, nvm current's job is to tell you node -v only iff the current node version is managed, otherwise it tells you system or none.

@jorgebucaran
Copy link
Owner

jorgebucaran commented Dec 5, 2020

I just released 2.0. Now there's an nvm current command.

$ nvm use latest 
Now using Node v15.3.0 (npm 7.0.14) ~/.local/share/nvm/v15.3.0/bin/node
$ nvm current
v15.3.0
$ nvm use system
Now using Node v15.2.0 (npm 7.0.10) /usr/local/bin/node
$ nvm current
system

If there's no system node (any previously installed node not managed with nvm) nothing will be printed and $status will be set to 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants