Adding node prompt that does not require NVM

There are now alternative version managers available, such as volta.sh.
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 nvm first, 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` this
function will pick it up and run `--version` on it, and therefore it will
now be displayed in the prompt.

Tested locally on OS-X/bash:

* with/without NVM
* with/without VOLTA
* with/without system node
pull/1944/head
Konstantin Gredeskoul 2021-09-12 23:35:38 -07:00
parent 93214cfcce
commit 040474499f
No known key found for this signature in database
GPG Key ID: F64DECB748F527EB
1 changed files with 17 additions and 1 deletions

View File

@ -381,8 +381,24 @@ function nvm_version_prompt {
fi fi
} }
function node_command_version_prompt {
local node_version
local node_command="$(command -v node)"
if [[ -n "${node_command}" && -x "${node_command}" ]]; then
node_version="$(${node_command} --version)"
echo -e "${NVM_THEME_PROMPT_PREFIX}${node_version}${NVM_THEME_PROMPT_SUFFIX}"
fi
}
function node_version_prompt { function node_version_prompt {
echo -e "$(nvm_version_prompt)" local node_version="$(nvm_version_prompt)"
if [[ -z "${node_version}" ]]; then
node_version="$(node_command_version_prompt)"
fi
if [[ -n "${node_version}" ]] ; then
echo -e "${node_version}"
fi
} }
function rvm_version_prompt { function rvm_version_prompt {