From 8ddda1fe5c22e21d621fa0bb045805dacf4f46ef Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Fri, 15 Apr 2022 09:41:25 -0500 Subject: [PATCH 1/4] feat: support plain old node as strategy to get node version --- themes/base.theme.bash | 18 +++++++++++++++++- .../powerline-multiline.theme.bash | 2 ++ .../powerline-naked/powerline-naked.theme.bash | 2 ++ .../powerline-plain/powerline-plain.theme.bash | 2 ++ themes/powerline/powerline.theme.bash | 2 ++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 92a56e5e..6854d66a 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -74,6 +74,9 @@ SCM_NONE_CHAR='○' NVM_THEME_PROMPT_PREFIX=' |' NVM_THEME_PROMPT_SUFFIX='|' +NODE_THEME_PROMPT_PREFIX=' |' +NODE_THEME_PROMPT_SUFFIX='|' + RVM_THEME_PROMPT_PREFIX=' |' RVM_THEME_PROMPT_SUFFIX='|' @@ -399,8 +402,21 @@ function nvm_version_prompt() { fi } +function node_native_version_prompt() { + local node + if which -s node; then + node=$(node --version 2> /dev/null) + echo -ne "${NODE_THEME_PROMPT_PREFIX-}${node}${NODE_THEME_PROMPT_SUFFIX-}" + fi +} + function node_version_prompt() { - nvm_version_prompt + NODE_VERSION_STRATEGY="${NODE_VERSION_STRATEGY:-nvm}" + if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then + nvm_version_prompt + elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then + node_native_version_prompt + fi } function rvm_version_prompt() { diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 48a1243e..9db10cb4 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -39,6 +39,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 2fb4137e..a5aaaa34 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -34,6 +34,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 6ff68e8f..162fb5ca 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -31,6 +31,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 49b397aa..2772a018 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -37,6 +37,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} From f7d21b5191b9c11741f6e1491e02bb47f486e304 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Fri, 15 Apr 2022 09:57:05 -0500 Subject: [PATCH 2/4] chore: update docs --- docs/themes-list/powerline-base.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/themes-list/powerline-base.rst b/docs/themes-list/powerline-base.rst index faa1af34..f38f940d 100644 --- a/docs/themes-list/powerline-base.rst +++ b/docs/themes-list/powerline-base.rst @@ -81,7 +81,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * ``python_venv`` - Python virtual environment information (\ ``virtualenv``\ , ``venv`` and ``conda`` supported) * ``ruby`` - Current ruby version if using ``rvm`` -* ``node`` - Current node version (only ``nvm`` is supported) +* ``node`` - Current node version (``nvm`` is the default strategy; set ``NODE_VERSION_STRATEGY`` to ``node`` to use ``node --version``) * ``scm`` - Version control information, ``git`` * ``terraform`` - Current terraform workspace * ``user_info`` - Current user From 06b4b014cf97fc68f9cad7448b3511df5c4830c8 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Thu, 19 May 2022 07:20:33 -0500 Subject: [PATCH 3/4] chore: use _command_exists based on MR feedback --- themes/base.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 6854d66a..22839158 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -404,7 +404,7 @@ function nvm_version_prompt() { function node_native_version_prompt() { local node - if which -s node; then + if _command_exists node; then node=$(node --version 2> /dev/null) echo -ne "${NODE_THEME_PROMPT_PREFIX-}${node}${NODE_THEME_PROMPT_SUFFIX-}" fi From 5913d222c5e437bfcbd30b092909017476a727ab Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Thu, 19 May 2022 07:25:36 -0500 Subject: [PATCH 4/4] chore: add log stmt based on MR feedback --- themes/base.theme.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 22839158..e25014f8 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -412,6 +412,9 @@ function node_native_version_prompt() { function node_version_prompt() { NODE_VERSION_STRATEGY="${NODE_VERSION_STRATEGY:-nvm}" + + _log_debug "node: using version strategy '$NODE_VERSION_STRATEGY'" + if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then nvm_version_prompt elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then