Optimization and allow find_file to receive regex

Renamed the find_file function to find_file_up_re to better describe
the behaviour.
This commit is contained in:
Hans Larsen 2022-01-21 11:02:44 -08:00
parent 7b195eb646
commit 6d817d97b8

View File

@ -895,7 +895,7 @@ function __bobthefish_prompt_desk -S -d 'Display current desk environment'
set_color normal set_color normal
end end
function __bobthefish_prompt_find_file -S -d 'Find a file by going up the parent directories' function __bobthefish_prompt_find_file_up_re -S -d 'Find file(s) (as a regex), going up the parent directories'
set -l dir "$argv[1]" set -l dir "$argv[1]"
set -l file "$argv[2]" set -l file "$argv[2]"
@ -903,12 +903,12 @@ function __bobthefish_prompt_find_file -S -d 'Find a file by going up the parent
return 1 return 1
end end
while [ "$dir" != '/' ] while [ "$dir" ]
if [ -f "$dir/$file" ] if string match -q -r "$dir/($file)\$" -- $dir/*
return return
end end
set dir (dirname "$dir") set dir (__bobthefish_dirname "$dir")
end end
return 1 return 1
end end
@ -920,12 +920,11 @@ function __bobthefish_prompt_node -S -d 'Display current node version'
set should_show 1 set should_show 1
else if [ "$theme_display_node" = 'rc' ] else if [ "$theme_display_node" = 'rc' ]
begin begin
__bobthefish_prompt_find_file "$PWD" .nvmrc __bobthefish_prompt_find_file_up_re "$PWD" '\.nvmrc|\.node-version'
or __bobthefish_prompt_find_file "$PWD" .node-version
end end
and set should_show 1 and set should_show 1
else if [ "$theme_display_node" = 'package' ] else if [ "$theme_display_node" = 'package' ]
__bobthefish_prompt_find_file "$PWD" package.json __bobthefish_prompt_find_file_up_re "$PWD" 'package\.json'
and set should_show 1 and set should_show 1
end end