From 310377a43ed09e813fa8e1a52e913b3785497334 Mon Sep 17 00:00:00 2001 From: wesbaker Date: Wed, 20 Jan 2021 16:28:53 -0500 Subject: [PATCH] Made the __bobthefish_prompt_nvm generic for nvm and fnm --- README.md | 6 ++--- fish_prompt.fish | 38 +++++++++++++++--------------- functions/__bobthefish_colors.fish | 28 +++++++++++----------- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 9652630..8aa4f2b 100644 --- a/README.md +++ b/README.md @@ -85,8 +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_fnm 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 @@ -125,8 +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_fnm`. If set to `yes`, will display current FNM 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/fish_prompt.fish b/fish_prompt.fish index 1d9bda9..f5f56e2 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -896,30 +896,30 @@ 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) [ -z $node_version -o "$node_version" = 'none' -o "$node_version" = 'system' ] and return - __bobthefish_start_segment $color_nvm - echo -ns $node_glyph $node_version ' ' - set_color normal -end - -function __bobthefish_prompt_nvm -S -d 'Display current node version through FNM' - [ "$theme_display_nvm" = 'yes' -a -n "$FNM_DIR" ] - or return - - set -l node_version (fnm current 2> /dev/null) - - [ -z $node_version -o "$node_version" = 'none' -o "$node_version" = 'system' ] - and return - - __bobthefish_start_segment $color_nvm + __bobthefish_start_segment $color_node echo -ns $node_glyph $node_version ' ' set_color normal end @@ -1139,7 +1139,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) 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