mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 01:51:14 -03:00
Support for command wrapping ("aliases")
Add the --wraps option to 'complete' and 'function'. This allows a command to (recursively) inherit the completions of a wrapped command. Fixes #393. When evaluating a completion, we inspect the entire "wrap chain" for a command, i.e. we follow the sequence of wrapping until we either hit a loop (which we silently ignore) or the end of the chain. We then evaluate completions as if the wrapping command were substituted with the wrapped command. Currently this only works for commands, i.e. 'complete --command gco --wraps git\ checkout' won't work (that would seem to encroaching on abbreviations anyways). It might be useful to show an error message for that case. The commandline builtin reflects the commandline with the wrapped command substituted in, so e.g. git completions (which inspect the command line) will just work. This sort of command line munging is also performed by 'complete -C' so it's not totally without precedent. 'alias will also now mark its generated function as wrapping the 'target.
This commit is contained in:
@@ -166,6 +166,21 @@ static void err(const wchar_t *blah, ...)
|
||||
wprintf(L"\n");
|
||||
}
|
||||
|
||||
// Joins a wcstring_list_t via commas
|
||||
static wcstring comma_join(const wcstring_list_t &lst)
|
||||
{
|
||||
wcstring result;
|
||||
for (size_t i=0; i < lst.size(); i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
result.push_back(L',');
|
||||
}
|
||||
result.append(lst.at(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#define do_test(e) do { if (! (e)) err(L"Test failed on line %lu: %s", __LINE__, #e); } while (0)
|
||||
|
||||
/* Test sane escapes */
|
||||
@@ -1924,6 +1939,18 @@ static void test_complete(void)
|
||||
do_test(completions.empty());
|
||||
|
||||
complete_set_variable_names(NULL);
|
||||
|
||||
/* Test wraps */
|
||||
do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1");
|
||||
complete_add_wrapper(L"wrapper1", L"wrapper2");
|
||||
do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1,wrapper2");
|
||||
complete_add_wrapper(L"wrapper2", L"wrapper3");
|
||||
do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1,wrapper2,wrapper3");
|
||||
complete_add_wrapper(L"wrapper3", L"wrapper1"); //loop!
|
||||
do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1,wrapper2,wrapper3");
|
||||
complete_remove_wrapper(L"wrapper1", L"wrapper2");
|
||||
do_test(comma_join(complete_get_wrap_chain(L"wrapper1")) == L"wrapper1");
|
||||
do_test(comma_join(complete_get_wrap_chain(L"wrapper2")) == L"wrapper2,wrapper3,wrapper1");
|
||||
}
|
||||
|
||||
static void test_1_completion(wcstring line, const wcstring &completion, complete_flags_t flags, bool append_only, wcstring expected, long source_line)
|
||||
|
||||
Reference in New Issue
Block a user