Eagerly abort wildcard completions for ** wildcards

Historically fish has not supported tab completing or autosuggesting
wildcards with **. Prior to this fix, we would test every file match,
discover the ** wildcard, and then ignore it. Instead look for **
wildcards at the top level.

This prevents autosuggesting with /** from chewing up your disk.
This commit is contained in:
ridiculousfish 2020-12-20 13:26:28 -08:00
parent 10362a70df
commit c2c729352e

View file

@ -851,7 +851,7 @@ void wildcard_expander_t::expand_literal_intermediate_segment_with_fuzz(const wc
void wildcard_expander_t::expand_last_segment(const wcstring &base_dir, DIR *base_dir_fp,
const wcstring &wc, const wcstring &prefix) {
wcstring name_str;
while (wreaddir(base_dir_fp, name_str)) {
while (!interrupted_or_overflowed() && wreaddir(base_dir_fp, name_str)) {
if (flags & expand_flag::for_completions) {
this->try_add_completion_result(base_dir + name_str, name_str, wc, prefix);
} else {
@ -992,6 +992,13 @@ wildcard_result_t wildcard_expand_string(const wcstring &wc, const wcstring &wor
return wildcard_result_t::no_match;
}
// We do not support tab-completing recursive (**) wildcards. This is historic behavior.
// Do not descend any directories if there is a ** wildcard.
if (flags.get(expand_flag::for_completions) &&
wc.find(ANY_STRING_RECURSIVE) != wcstring::npos) {
return wildcard_result_t::no_match;
}
// Compute the prefix and base dir. The prefix is what we prepend for filesystem operations
// (i.e. the working directory), the base_dir is the part of the wildcard consumed thus far,
// which we also have to append. The difference is that the base_dir is returned as part of the