Closed IlanCosman closed 3 years ago
@IlanCosman What would nvm current
do?
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.
@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
?
In particular, it returns system
if it's not a managed version.
Sorry, but I don't understand how this is useful. What does Tide plan to do with this, and why not node -v
?
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.
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.
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
.
https://github.com/IlanCosman/tide/pull/10#issuecomment-663875738
@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.
Sounds good, thanks for your attention on this :)
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
.
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.
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.