From af5aac28c4ee68cddd60aff47d1afb6d1f7c898f Mon Sep 17 00:00:00 2001 From: Wes Baker Date: Sun, 24 Jan 2021 17:14:30 -0500 Subject: [PATCH] Add FNM as an alternative to NVM (#292) * Add FNM as an alternative to NVM * Made the __bobthefish_prompt_nvm generic for nvm and fnm * Hide errors on node_manager current * Check for color_nvm and set color_node based on that --- README.md | 6 +++--- functions/__bobthefish_colors.fish | 28 ++++++++++++++-------------- functions/fish_prompt.fish | 29 +++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 8b8ad44..8aa4f2b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ This theme is based loosely on [agnoster][agnoster]. * Current RVM, rbenv or chruby (Ruby) version * Current virtualenv (Python) version * _If you use virtualenv, you will probably need to disable the default virtualenv prompt, since it doesn't play nice with fish: `set -x VIRTUAL_ENV_DISABLE_PROMPT 1`_ - * Current NVM version (Nodejs) (inactive by default; see configurations in the next paragraph) + * Current NVM/FNM version (Nodejs) (inactive by default; see configurations in the next paragraph) * Abbreviated parent directory * Current directory, or Git or Mercurial project name * Current project's repo branch (branch-glyph master) or detached head (`➦` d0dfd9b) @@ -85,7 +85,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_node yes set -g theme_display_user ssh set -g theme_display_hostname ssh set -g theme_display_vi no @@ -124,7 +124,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_node`. If set to `yes`, will display current NVM or FNM node 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/functions/__bobthefish_colors.fish b/functions/__bobthefish_colors.fish index 162959b..1ee71d2 100644 --- a/functions/__bobthefish_colors.fish +++ b/functions/__bobthefish_colors.fish @@ -33,7 +33,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username white black --bold set -x color_hostname white black set -x color_rvm brmagenta $colorfg --bold - set -x color_nvm brgreen $colorfg --bold + set -x color_node brgreen $colorfg --bold set -x color_virtualfish brblue $colorfg --bold set -x color_virtualgo brblue $colorfg --bold set -x color_desk brblue $colorfg --bold @@ -68,7 +68,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username black white --bold set -x color_hostname black white set -x color_rvm brmagenta $colorfg --bold - set -x color_nvm brgreen $colorfg --bold + set -x color_node brgreen $colorfg --bold set -x color_virtualfish brblue $colorfg --bold set -x color_virtualgo brblue $colorfg --bold set -x color_desk brblue $colorfg --bold @@ -103,7 +103,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username brgrey white --bold set -x color_hostname brgrey white set -x color_rvm brmagenta $colorfg --bold - set -x color_nvm brgreen $colorfg --bold + set -x color_node brgreen $colorfg --bold set -x color_virtualfish brblue $colorfg --bold set -x color_virtualgo brblue $colorfg --bold set -x color_desk brblue $colorfg --bold @@ -138,7 +138,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username grey black --bold set -x color_hostname grey black set -x color_rvm brmagenta $colorfg --bold - set -x color_nvm brgreen $colorfg --bold + set -x color_node brgreen $colorfg --bold set -x color_virtualfish brblue $colorfg --bold set -x color_virtualgo brblue $colorfg --bold set -x color_desk brblue $colorfg --bold @@ -179,7 +179,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $grey $blue --bold set -x color_hostname $grey $blue set -x color_rvm $red $grey --bold - set -x color_nvm $green $white --bold + set -x color_node $green $white --bold set -x color_virtualfish $blue $grey --bold set -x color_virtualgo $blue $grey --bold set -x color_desk $blue $grey --bold @@ -231,7 +231,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $base02 $base0D --bold set -x color_hostname $base02 $base0D set -x color_rvm $base08 $colorfg --bold - set -x color_nvm $base0B $colorfg --bold + set -x color_node $base0B $colorfg --bold set -x color_virtualfish $base0D $colorfg --bold set -x color_virtualgo $base0D $colorfg --bold set -x color_desk $base0D $colorfg --bold @@ -283,7 +283,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $base02 $base0D --bold set -x color_hostname $base02 $base0D set -x color_rvm $base08 $colorfg --bold - set -x color_nvm $base0B $colorfg --bold + set -x color_node $base0B $colorfg --bold set -x color_virtualfish $base0D $colorfg --bold set -x color_virtualgo $base0D $colorfg --bold set -x color_desk $base0D $colorfg --bold @@ -335,7 +335,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $base2 $blue --bold set -x color_hostname $base2 $blue set -x color_rvm $red $colorfg --bold - set -x color_nvm $green $colorfg --bold + set -x color_node $green $colorfg --bold set -x color_virtualfish $cyan $colorfg --bold set -x color_virtualgo $cyan $colorfg --bold set -x color_desk $cyan $colorfg --bold @@ -387,7 +387,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $base02 $blue --bold set -x color_hostname $base02 $blue set -x color_rvm $red $colorfg --bold - set -x color_nvm $green $colorfg --bold + set -x color_node $green $colorfg --bold set -x color_virtualfish $cyan $colorfg --bold set -x color_virtualgo $cyan $colorfg --bold set -x color_desk $cyan $colorfg --bold @@ -432,7 +432,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $grey[1] $blue[3] --bold set -x color_hostname $grey[1] $blue[3] set -x color_rvm $ruby_red $grey[1] --bold - set -x color_nvm $green $grey[1] --bold + set -x color_node $green $grey[1] --bold set -x color_virtualfish $blue[2] $grey[1] --bold set -x color_virtualgo $blue[2] $grey[1] --bold set -x color_desk $blue[2] $grey[1] --bold @@ -476,7 +476,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $fg[3] $blue[2] --bold set -x color_hostname $fg[3] $blue[2] set -x color_rvm $red[2] $fg[2] --bold - set -x color_nvm $green[1] $fg[2] --bold + set -x color_node $green[1] $fg[2] --bold set -x color_virtualfish $blue[2] $fg[2] --bold set -x color_virtualgo $blue[2] $fg[2] --bold set -x color_desk $blue[2] $fg[2] --bold @@ -522,7 +522,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $selection $cyan --bold set -x color_hostname $selection $cyan set -x color_rvm $red $bg --bold - set -x color_nvm $green $bg --bold + set -x color_node $green $bg --bold set -x color_virtualfish $comment $bg --bold set -x color_virtualgo $cyan $bg --bold set -x color_desk $comment $bg --bold @@ -574,7 +574,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $base02 $base0D --bold set -x color_hostname $base02 $base0D set -x color_rvm $base09 $colorfg --bold - set -x color_nvm $base09 $colorfg --bold + set -x color_node $base09 $colorfg --bold set -x color_virtualfish $base09 $colorfg --bold set -x color_virtualgo $base09 $colorfg --bold set -x color_desk $base09 $colorfg --bold @@ -619,7 +619,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe set -x color_username $grey[1] $blue[3] --bold set -x color_hostname $grey[1] $blue[3] set -x color_rvm $ruby_red $grey[1] --bold - set -x color_nvm $green[1] $white --bold + set -x color_node $green[1] $white --bold set -x color_virtualfish $blue[2] $grey[1] --bold set -x color_virtualgo $go_blue $black --bold set -x color_desk $blue[2] $grey[1] --bold diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index e0a653e..a37fae6 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -39,7 +39,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_node yes # set -g theme_avoid_ambiguous_glyphs yes # set -g theme_powerline_fonts no # set -g theme_nerd_fonts yes @@ -895,16 +895,33 @@ 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_node -S -d 'Display current node version' + [ "$theme_display_node" = "yes" -o "$theme_display_nvm" = 'yes' ] or return - set -l node_version (nvm current 2> /dev/null) + set -l node_manager + set -l node_manager_dir + + if type -fq nvm + set node_manager "nvm" + set node_manager_dir $NVM_DIR + else if type -fq fnm + set node_manager "fnm" + set node_manager_dir $FNM_DIR + end + + [ -n "$node_manager_dir" ] + or return + + set -l node_version ("$node_manager" current 2> /dev/null) [ -z $node_version -o "$node_version" = 'none' -o "$node_version" = 'system' ] and return - __bobthefish_start_segment $color_nvm + [ -n "$color_nvm" ] + and set -x color_node $color_nvm + + __bobthefish_start_segment $color_node echo -ns $node_glyph $node_version ' ' set_color normal end @@ -1124,7 +1141,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_node set -l real_pwd (__bobthefish_pwd)