From 040474499f066862761f231a30831ee1c74d22d2 Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Sun, 12 Sep 2021 23:35:38 -0700 Subject: [PATCH] Adding node prompt that does not require NVM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- themes/base.theme.bash | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a6ee71ec..b5211f53 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -381,8 +381,24 @@ function nvm_version_prompt { 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 { - 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 {