Skip to content

Commit 1eaed8c

Browse files
authored
Add more options to conditionally show node version (#315)
1 parent e691500 commit 1eaed8c

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ set -g theme_newline_prompt '$ '
124124
**Prompt options**
125125

126126
- `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.
127-
- `theme_display_node`. If set to `yes`, will display current NVM or FNM node version.
127+
- `theme_display_node`. If set to `always`, will display current NPM, NVM or FNM node version. If set to `yes`, will display the version if an `.nvmrc`, `.node-version` or `package.json` file is found in the parent directories.
128128
- `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.
129129
- `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.
130130
- `theme_display_k8s_context`. This feature is disabled by default. Use `yes` to show the current kubernetes context (`> kubectl config current-context`).

functions/fish_prompt.fish

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,42 @@ function __bobthefish_prompt_desk -S -d 'Display current desk environment'
895895
set_color normal
896896
end
897897

898+
function __bobthefish_prompt_find_file_up -S -d 'Find file(s), going up the parent directories'
899+
set -l dir "$argv[1]"
900+
set -l files $argv[2..]
901+
902+
if test -z "$dir"
903+
or test -z "$files"
904+
return 1
905+
end
906+
907+
while [ "$dir" ]
908+
for f in $files
909+
if [ -e "$dir/$f" ]
910+
return
911+
end
912+
end
913+
914+
[ "$dir" = '/' ]
915+
and return 1
916+
917+
set dir (__bobthefish_dirname "$dir")
918+
end
919+
return 1
920+
end
921+
898922
function __bobthefish_prompt_node -S -d 'Display current node version'
899-
[ "$theme_display_node" = 'yes' -o "$theme_display_nvm" = 'yes' ]
900-
or return
923+
set -l should_show
924+
925+
if [ "$theme_display_node" = 'always' -o "$theme_display_nvm" = 'yes' ]
926+
set should_show 1
927+
else if [ "$theme_display_node" = 'yes' ]
928+
__bobthefish_prompt_find_file_up "$PWD" package.json .nvmrc .node-version
929+
and set should_show 1
930+
end
931+
932+
[ -z "$should_show" ]
933+
and return
901934

902935
set -l node_manager
903936
set -l node_manager_dir

0 commit comments

Comments
 (0)