From 02c7be204f4f1d3bda024bf71b61064b2c8b8231 Mon Sep 17 00:00:00 2001 From: shaun <512005+a2bb892@users.noreply.github.com> Date: Wed, 13 Nov 2019 23:24:56 -0700 Subject: [PATCH] Add support for nodenv This will make is so that the current Node.js version can be displayed using either nvm or nodenv. I also changed the configuration setting `theme_display_nvm` to `theme_display_nodejs`. --- README.md | 4 ++-- fish_prompt.fish | 35 ++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 776d104..cc5013f 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ set -g theme_display_hg yes set -g theme_display_virtualenv no set -g theme_display_nix no set -g theme_display_ruby no -set -g theme_display_nvm yes +set -g theme_display_nodejs yes set -g theme_display_user ssh set -g theme_display_hostname ssh set -g theme_display_vi no @@ -119,7 +119,7 @@ set -g theme_newline_prompt '$ ' **Prompt options** - `theme_display_ruby`. Use `no` to completely hide all information about Ruby version. By default Ruby version displayed if there is the difference from default settings. -- `theme_display_nvm`. If set to `yes`, will display current NVM node version. +- `theme_display_nodejs`. If set to `yes`, will display current Node.js version. - `theme_display_vagrant`. This feature is disabled by default, use `yes` to display Vagrant status in your prompt. Please note that only the VirtualBox and VMWare providers are supported. - `theme_display_vi`. By default the vi mode indicator will be shown if vi or hybrid key bindings are enabled. Use `no` to hide the indicator, or `yes` to show the indicator. - `theme_display_k8s_context`. This feature is disabled by default. Use `yes` to show the current kubernetes context (`> kubectl config current-context`). diff --git a/fish_prompt.fish b/fish_prompt.fish index 4c47f7f..8a1913c 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -37,7 +37,7 @@ # set -g theme_display_hostname ssh # set -g theme_display_sudo_user yes # set -g theme_display_vi no -# set -g theme_display_nvm yes +# set -g theme_display_nodejs yes # set -g theme_avoid_ambiguous_glyphs yes # set -g theme_powerline_fonts no # set -g theme_nerd_fonts yes @@ -850,14 +850,35 @@ function __bobthefish_prompt_desk -S -d 'Display current desk environment' set_color normal end -function __bobthefish_prompt_nvm -S -d 'Display current node version through NVM' - [ "$theme_display_nvm" = 'yes' -a -n "$NVM_DIR" ] +function __bobthefish_prompt_nodejs -S -d 'Display current Node.js version' + [ "$theme_display_nodejs" = 'yes' -o "$theme_display_nvm" = 'yes' ] or return - set -l node_version (nvm current 2> /dev/null) + set -l node_version + if type -q nvm + [ -n "$NVM_DIR" ] + or return - [ -z $node_version -o "$node_version" = 'none' -o "$node_version" = 'system' ] - and return + set node_version (nvm current 2> /dev/null) + + [ -z $node_version -o "$node_version" = 'none' -o "$node_version" = 'system' ] + and return + else if type -fq nodenv + set node_version (nodenv version-name) + + # Don't show global node version... + set -q NODENV_ROOT + or set -l NODENV_ROOT $HOME/.nodenv + + [ -e "$NODENV_ROOT/version" ] + and read -l global_node_version < "$NODENV_ROOT/version" + + [ "$global_node_version" ] + or set -l global_node_version system + + [ "$node_version" = "$global_node_version" ] + and return + end __bobthefish_start_segment $color_nvm echo -ns $node_glyph $node_version ' ' @@ -1076,7 +1097,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' __bobthefish_prompt_rubies __bobthefish_prompt_virtualfish __bobthefish_prompt_virtualgo - __bobthefish_prompt_nvm + __bobthefish_prompt_nodejs set -l real_pwd (__bobthefish_pwd)