From c2c729352e17f6e8cc54c0a40a4ffddc6532015f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 20 Dec 2020 13:26:28 -0800 Subject: [PATCH] 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. --- src/wildcard.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 5b5a76dc3..2db059237 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -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