From b935ddd309e042c287ea3f7b8a81438c6e1d176c Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Mon, 13 Sep 2021 00:11:16 -0700 Subject: [PATCH 1/4] `node_version_prompt` should work without NVM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- themes/base.theme.bash | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 4d6a1b7f51..853b50c2ff 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -386,6 +386,27 @@ function hg_prompt_vars { fi } +function node_command_version_prompt { + local node_version + local node_command="$(command -v node)" + if [[ -n "${node_command}" ]]; then + node_version="$(${node_command} --version 2>/dev/null)" + if [[ -n ${node_version} ]]; then + echo -e "${NVM_THEME_PROMPT_PREFIX}${node_version}${NVM_THEME_PROMPT_SUFFIX}" + fi + fi +} + +function node_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 nvm_version_prompt { local node if declare -f -F nvm &> /dev/null; then @@ -395,10 +416,6 @@ function nvm_version_prompt { fi } -function node_version_prompt { - echo -e "$(nvm_version_prompt)" -} - function rvm_version_prompt { if which rvm &> /dev/null; then rvm=$(rvm-prompt) || return From 1a96dd1947587d521049d0e8a188bcff1c6eee99 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 23 Feb 2022 16:00:52 -0800 Subject: [PATCH 2/4] lib/theme: use `_command_exists()` --- themes/base.theme.bash | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 853b50c2ff..08929ecbdd 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -386,23 +386,22 @@ function hg_prompt_vars { fi } -function node_command_version_prompt { +function node_command_version_prompt() { local node_version - local node_command="$(command -v node)" - if [[ -n "${node_command}" ]]; then - node_version="$(${node_command} --version 2>/dev/null)" + if _command_exists node; then + node_version="$(node --version 2> /dev/null)" if [[ -n ${node_version} ]]; then echo -e "${NVM_THEME_PROMPT_PREFIX}${node_version}${NVM_THEME_PROMPT_SUFFIX}" fi fi } -function node_version_prompt { +function node_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 + if [[ -n "${node_version}" ]]; then echo -e "${node_version}" fi } From f7c32563f4dae1ae9eaaa5dfa9616a1fc852fbf2 Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Thu, 24 Feb 2022 13:29:40 -0800 Subject: [PATCH 3/4] Update themes/base.theme.bash Co-authored-by: John D Pell <52194+gaelicWizard@users.noreply.github.com> --- themes/base.theme.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 08929ecbdd..80763f28fa 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -397,7 +397,8 @@ function node_command_version_prompt() { } function node_version_prompt() { - local node_version="$(nvm_version_prompt)" + local node_version + node_version="$(nvm_version_prompt)" if [[ -z "${node_version}" ]]; then node_version="$(node_command_version_prompt)" fi From 78d19e76c062f26449ee20f2c7e9689bf452eeff Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Thu, 24 Mar 2022 14:49:21 -0700 Subject: [PATCH 4/4] Fix node and ruby colors --- themes/powerline-multiline/powerline-multiline.theme.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 48a1243e03..c716a5b9b2 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -40,13 +40,13 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} -NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} +NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=28} RVM_THEME_PROMPT_PREFIX="" RVM_THEME_PROMPT_SUFFIX="" RBENV_THEME_PROMPT_PREFIX="" RBENV_THEME_PROMPT_SUFFIX="" -RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=161} +RUBY_THEME_PROMPT_COLOR=${POWERLINE_RUBY_COLOR:=1} RUBY_CHAR=${POWERLINE_RUBY_CHAR:="❲r❳ "} TERRAFORM_THEME_PROMPT_COLOR=${POWERLINE_TERRAFORM_COLOR:=161}