function: Don't list empty function names and directories

This commit is contained in:
Fabian Boehm 2022-10-29 10:24:03 +02:00
parent daf5e11179
commit 8d7662335e
2 changed files with 41 additions and 3 deletions

View File

@ -127,12 +127,16 @@ static void autoload_names(std::unordered_set<wcstring> &names, bool get_hidden)
if (!get_hidden && fn[0] == L'_') continue;
suffix = std::wcsrchr(fn, L'.');
if (suffix && (std::wcscmp(suffix, L".fish") == 0)) {
// We need a ".fish" *suffix*, it can't be the entire name.
if (suffix && suffix != fn && (std::wcscmp(suffix, L".fish") == 0)) {
// Also ignore directories.
if (!entry->is_dir()) {
wcstring name(fn, suffix - fn);
names.insert(name);
}
}
}
}
}
void function_add(wcstring name, std::shared_ptr<function_properties_t> props) {

View File

@ -114,4 +114,38 @@ end
functions -q; or echo False
#CHECK: False
# See that we don't count a file with an empty function name,
# or directories
set -l tmpdir (mktemp -d)
touch $tmpdir/.fish
mkdir $tmpdir/directory.fish
touch $tmpdir/actual_function.fish
begin
set -l fish_function_path $tmpdir
functions
end
# CHECK: actual_function
# these are functions defined either in this file,
# or eagerly in share/config.fish.
# I don't know of a way to ignore just them.
#
# CHECK: bg
# CHECK: disown
# CHECK: fg
# CHECK: fish_command_not_found
# CHECK: fish_sigtrap_handler
# CHECK: frob
# CHECK: kill
# CHECK: name1
# CHECK: name1a
# CHECK: name3
# CHECK: name3a
# CHECK: t
# CHECK: wait
rm -r $tmpdir
exit 0