mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
rename FOR_COMPLETIONS to EXPAND_FOR_COMPLETIONS
This is yet clearer
This commit is contained in:
parent
d2049edcab
commit
602e9cebd9
6 changed files with 28 additions and 31 deletions
|
@ -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;
|
||||
|
|
|
@ -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<completion_t> *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<completion_t> *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<completion_t> *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<completion_t> *output, expa
|
|||
|
||||
std::vector<completion_t> 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<completion_t> *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<completion_t> 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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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<completion_t> 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'/');
|
||||
|
|
|
@ -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).
|
||||
|
|
Loading…
Reference in a new issue