diff --git a/src/complete.cpp b/src/complete.cpp index 2e4d69ce1..ed30776dc 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -1140,7 +1140,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool if (use_command) { - if (expand_string(str_cmd, &this->completions, FOR_COMPLETIONS | EXECUTABLES_ONLY | this->expand_flags(), NULL) != EXPAND_ERROR) + if (expand_string(str_cmd, &this->completions, EXPAND_FOR_COMPLETIONS | EXECUTABLES_ONLY | this->expand_flags(), NULL) != EXPAND_ERROR) { if (this->wants_descriptions()) { @@ -1150,7 +1150,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool } if (use_implicit_cd) { - if (!expand_string(str_cmd, &this->completions, FOR_COMPLETIONS | DIRECTORIES_ONLY | this->expand_flags(), NULL)) + if (!expand_string(str_cmd, &this->completions, EXPAND_FOR_COMPLETIONS | DIRECTORIES_ONLY | this->expand_flags(), NULL)) { // Not valid as implicit cd. } @@ -1180,7 +1180,7 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool size_t prev_count = this->completions.size(); if (expand_string(nxt_completion, &this->completions, - FOR_COMPLETIONS | EXECUTABLES_ONLY | this->expand_flags(), NULL) != EXPAND_ERROR) + EXPAND_FOR_COMPLETIONS | EXECUTABLES_ONLY | this->expand_flags(), NULL) != EXPAND_ERROR) { /* For all new completions, if COMPLETE_NO_CASE is set, then use only the last path component */ for (size_t i=prev_count; i< this->completions.size(); i++) @@ -1617,7 +1617,7 @@ bool completer_t::complete_param(const wcstring &scmd_orig, const wcstring &spop */ void completer_t::complete_param_expand(const wcstring &str, bool do_file, bool directories_only) { - expand_flags_t flags = EXPAND_SKIP_CMDSUBST | FOR_COMPLETIONS | this->expand_flags(); + expand_flags_t flags = EXPAND_SKIP_CMDSUBST | EXPAND_FOR_COMPLETIONS | this->expand_flags(); if (! do_file) flags |= EXPAND_SKIP_WILDCARDS; diff --git a/src/expand.cpp b/src/expand.cpp index b5761610a..620429c4f 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -616,7 +616,7 @@ static int find_job(const struct find_job_data_t *info) This is a numeric job string, like '%2' */ - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { job_iterator_t jobs; while ((j = jobs.next())) @@ -672,7 +672,7 @@ static int find_job(const struct find_job_data_t *info) size_t offset; if (match_pid(j->command(), proc, flags, &offset)) { - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { append_completion(&completions, j->command_wcstr() + offset + wcslen(proc), @@ -703,7 +703,7 @@ static int find_job(const struct find_job_data_t *info) size_t offset; if (match_pid(p->actual_cmd, proc, flags, &offset)) { - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { append_completion(&completions, wcstring(p->actual_cmd, offset + wcslen(proc)), @@ -763,7 +763,7 @@ static void find_process(const wchar_t *proc, expand_flags_t flags, std::vector< size_t offset; if (match_pid(process_name, proc, flags, &offset)) { - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { append_completion(out, process_name.c_str() + offset + wcslen(proc), @@ -808,7 +808,7 @@ static bool expand_pid(const wcstring &instr_with_sep, expand_flags_t flags, std /* We know we are a process expansion now */ assert(in[0] == PROCESS_EXPAND); - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { if (wcsncmp(in+1, SELF_STR, wcslen(in+1))==0) { @@ -849,7 +849,7 @@ static bool expand_pid(const wcstring &instr_with_sep, expand_flags_t flags, std if (prev_count == out->size()) { - if (!(flags & FOR_COMPLETIONS)) + if (!(flags & EXPAND_FOR_COMPLETIONS)) { /* We failed to find anything */ append_syntax_error(errors, 1, FAILED_EXPANSION_PROCESS_ERR_MSG, escape(in+1, ESCAPE_NO_QUOTED).c_str()); @@ -1300,7 +1300,7 @@ static int expand_brackets(parser_t &parser, const wcstring &instr, int flags, s if (bracket_count > 0) { - if (!(flags & FOR_COMPLETIONS)) + if (!(flags & EXPAND_FOR_COMPLETIONS)) { syntax_error = true; } @@ -1682,7 +1682,7 @@ int expand_string(const wcstring &input, std::vector *output, expa size_t i; int res = EXPAND_OK; - if ((!(flags & FOR_COMPLETIONS)) && expand_is_clean(input.c_str())) + if ((!(flags & EXPAND_FOR_COMPLETIONS)) && expand_is_clean(input.c_str())) { append_completion(output, input); return EXPAND_OK; @@ -1761,7 +1761,7 @@ int expand_string(const wcstring &input, std::vector *output, expa if (!(EXPAND_SKIP_HOME_DIRECTORIES & flags)) expand_home_directory(next); - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { if (! next.empty() && next.at(0) == PROCESS_EXPAND) { @@ -1799,7 +1799,7 @@ int expand_string(const wcstring &input, std::vector *output, expa { // Don't do wildcard expansion for executables. See #785. So do nothing here. } - else if (((flags & FOR_COMPLETIONS) && (!(flags & EXPAND_SKIP_WILDCARDS))) || + else if (((flags & EXPAND_FOR_COMPLETIONS) && (!(flags & EXPAND_SKIP_WILDCARDS))) || has_wildcard) { wcstring start, rest; @@ -1817,7 +1817,7 @@ int expand_string(const wcstring &input, std::vector *output, expa std::vector expanded; wc_res = wildcard_expand_string(rest, start, flags, &expanded); - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { out->insert(out->end(), expanded.begin(), expanded.end()); } @@ -1850,7 +1850,7 @@ int expand_string(const wcstring &input, std::vector *output, expa } else { - if (!(flags & FOR_COMPLETIONS)) + if (!(flags & EXPAND_FOR_COMPLETIONS)) { append_completion(out, next); } @@ -1874,7 +1874,7 @@ bool expand_one(wcstring &string, expand_flags_t flags, parse_error_list_t *erro std::vector completions; bool result = false; - if ((!(flags & FOR_COMPLETIONS)) && expand_is_clean(string.c_str())) + if ((!(flags & EXPAND_FOR_COMPLETIONS)) && expand_is_clean(string.c_str())) { return true; } diff --git a/src/expand.h b/src/expand.h index 94f2c98cf..a6b287f4c 100644 --- a/src/expand.h +++ b/src/expand.h @@ -36,12 +36,9 @@ enum EXPAND_SKIP_WILDCARDS = 1 << 2, /** - Incomplete matches in the last segment are ok (for tab - completion). An incomplete match is a wildcard that matches a - prefix of the filename. If accept_incomplete is true, only the - remainder of the string is returned. + The expansion is being done for tab or auto completions. Returned completions may have the wildcard as a prefix instead of a match. */ - FOR_COMPLETIONS = 1 << 3, + EXPAND_FOR_COMPLETIONS = 1 << 3, /** Only match files that are executable by the current user. Only applicable together with ACCEPT_INCOMPLETE. */ EXECUTABLES_ONLY = 1 << 4, diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 5df91f1d8..04d12cedb 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1435,7 +1435,7 @@ static void test_expand() expand_test(L"a*", EXPAND_SKIP_WILDCARDS, L"a*", 0, L"Cannot skip wildcard expansion"); - expand_test(L"/bin/l\\0", FOR_COMPLETIONS, 0, + expand_test(L"/bin/l\\0", EXPAND_FOR_COMPLETIONS, 0, L"Failed to handle null escape in expansion"); expand_test(L"foo\\$bar", EXPAND_SKIP_VARIABLES, L"foo$bar", 0, @@ -1475,7 +1475,7 @@ static void test_expand() L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax", L"/tmp/fish_expand_test/bax/xxx", L"/tmp/fish_expand_test/baz", L"/tmp/fish_expand_test/baz/xxx", wnull, L"Glob did the wrong thing"); - expand_test(L"/tmp/fish_expand_test/BA", FOR_COMPLETIONS, + expand_test(L"/tmp/fish_expand_test/BA", EXPAND_FOR_COMPLETIONS, L"/tmp/fish_expand_test/bar", L"/tmp/fish_expand_test/bax/", L"/tmp/fish_expand_test/baz/", wnull, L"Case insensitive test did the wrong thing"); diff --git a/src/wildcard.cpp b/src/wildcard.cpp index 66318546a..795423a8c 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -769,7 +769,7 @@ void wildcard_expander_t::expand_trailing_slash(const wcstring &base_dir) return; } - if (! (flags & FOR_COMPLETIONS)) + if (! (flags & EXPAND_FOR_COMPLETIONS)) { /* Trailing slash and not accepting incomplete, e.g. `echo /tmp/`. Insert this file if it exists. */ if (waccess(base_dir, F_OK)) @@ -840,7 +840,7 @@ void wildcard_expander_t::expand_last_segment(const wcstring &base_dir, DIR *bas wcstring name_str; while (wreaddir(base_dir_fp, name_str)) { - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { /* Test for matches before stating file, so as to minimize the number of calls to the much slower stat function. The only expand flag we care about is EXPAND_FUZZY_MATCH; we have no complete flags. */ std::vector local_matches; @@ -1018,7 +1018,7 @@ static int wildcard_expand_internal(const wchar_t *wc, const size_t base_dir_len = wcslen(base_dir); const size_t wc_len = wcslen(wc); - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { /* Avoid excessive number of returned matches for wc ending with a * @@ -1083,7 +1083,7 @@ static int wildcard_expand_internal(const wchar_t *wc, The last wildcard segment is empty. Insert everything if completing, the directory itself otherwise. */ - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { wcstring next; while (wreaddir(dir, next)) @@ -1111,7 +1111,7 @@ static int wildcard_expand_internal(const wchar_t *wc, wcstring name_str; while (wreaddir(dir, name_str)) { - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { const wcstring long_name = make_path(base_dir, name_str); @@ -1296,7 +1296,7 @@ static int wildcard_expand(const wchar_t *wc, wildcard_expander_t expander(flags, out); expander.expand(base_dir, wc); - if (flags & FOR_COMPLETIONS) + if (flags & EXPAND_FOR_COMPLETIONS) { wcstring wc_base; const wchar_t *wc_base_ptr = wcsrchr(wc, L'/'); diff --git a/src/wildcard.h b/src/wildcard.h index 9325bb4cc..37b53fd2f 100644 --- a/src/wildcard.h +++ b/src/wildcard.h @@ -59,7 +59,7 @@ enum \param wc The wildcard string \param base_dir The base directory of the filesystem to perform the match against - \param flags flags for the search. Can be any combination of FOR_COMPLETIONS and EXECUTABLES_ONLY + \param flags flags for the search. Can be any combination of EXPAND_FOR_COMPLETIONS and EXECUTABLES_ONLY \param out The list in which to put the output \return 1 if matches where found, 0 otherwise. Return -1 on abort (I.e. ^C was pressed).