-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
node_version_prompt
should work without NVM
#1946
base: master
Are you sure you want to change the base?
Conversation
5a94e66
to
c612a65
Compare
Adding `node` prompt that does not depend on `nvm` and will work with other version managers as well. There are now alternative version managers available, such as a much more streamlined [volta.sh](https://volta.sh). It feels like a deja-vu of `rvm` to `rbenv` switch, all over again. Regardless, we should be able to show the current `node` version whether you are using NVM, VOLTA or a hot potato. I decided not to add dedicated PREFIX variables for now, but it can be done later. We still check if `nvm` prompt returns something first because the `declare` check is practically free, and if it returns something — we use it. Only if the output of NVM is blank do we use the new function to grab the version of NodeJS. There is a caveat — if `node` is installed with the OS, eg `/usr/bin/node` the new function will now pick up the version of that "system" node and show it. Therefore "system" node version will now be visible in the prompt of those who added `node` component to their prompt. Personally, I believe this is the correct behavior, because why should we hide the system node version if that's what's available and in the PATH? We shouldn't. In fact, I think it's rather confusing that previously we wouldn't show the system node version at all. Tested locally on OS-X/bash: * with/without NVM * with/without VOLTA * with/without system node
c612a65
to
b935ddd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kigster, great addition!
It seems like the lint stage is failing, so you probably need to fix that.
Other than that- I would be delighted if you could add tests for this. You can add a mock nvm/node
similar to whats being done in base.theme.svn.bats
what do you think?
@kigster, I opened kigster#3 which fixes the linting failure and alsö addresses @NoahGorny's suggestion. If you accept that PR, then it will automatically update this PR, which I then think is ready to merge. |
@gaelicWizard Thank you so much! My apologies, I started a new job and this fell off my radar. Glad you were able to finish it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test failure with upower
should be fixed in #2061. The linting error just needs a new line, suggested in my comment
Co-authored-by: John D Pell <[email protected]>
@NoahGorny, this one seems good to go, except for tests. I'm about to overhaul the BATS infra so I'm willing to add any missing coverage at that point unless @kigster has some tests up his sleeve. |
I don't have anything at the moment, like I said — new job :) |
Conflicts resolved, any chance to get this merged? |
Also, locally with |
The
I am certain this change has nothing to do with this failure. |
local node_version | ||
if _command_exists node; then | ||
node_version="$(node --version 2> /dev/null)" | ||
if [[ -n ${node_version} ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check would give a false positive when using version management shims that are common with tools like asdf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify? What do you mean by a false positive?
if node --version
returns a non-empty output, doesn't that mean that this is the current node version? If so, why not show it in the prompt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems good, but needs a new merge from master because there are conflicts. please resolve the conflicts and I'll merge it.
Sounds good. I noticed the same problem with ruby. Should I submit a separate PR for Ruby or include it here? |
new issue = new PR. thanks! |
Description
Adding
node
prompt that does not depend onnvm
and will work with other version managers as well.Motivation and Context
There are now alternative version managers available, such as a much more streamlined volta.sh. It feels like a deja-vu of
rvm
torbenv
switch, all over again.In any case, we should be able to show node version regardless of whether you are using NVM or not.
I decided not to add dedicated PREFIX variables for now, but it can be done later.
We still check if
nvm
prompt returns something first because thedeclare
check is practically free, and if it returns something — we use it. Only if the output of NVM is blank do we use the new function to grab the version of NodeJS.There is a caveat — if
node
is installed with the OS, eg/usr/bin/node
the new function will now pick up the version of that "system" node and show it. Therefore "system" node version will now be visible in the prompt of those who addednode
component to their prompt. Personally, I believe this is the correct behavior, because why should we hide the system node version if that's what's available and in the PATH? We shouldn't. In fact, I think it's rather confusing that previously we wouldn't show the system node version at all.How Has This Been Tested?
Tested locally on OS-X/bash:
Screenshots (if appropriate):
Powerline Multiline with VOLTA version manager and no NVM:

Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.