diff options
author | 2014-08-15 18:14:36 -0700 | |
---|---|---|
committer | 2014-08-15 18:14:36 -0700 | |
commit | 06400b83b188156f31ed92216ec27122d29f88cd (patch) | |
tree | 2f9cec409aba50449638c8d4361b4dafe530f3ec /builtin.cpp | |
parent | fe68d30be97853865b24ad5f5998d3e50769f860 (diff) |
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.
Diffstat (limited to 'builtin.cpp')
-rw-r--r-- | builtin.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/builtin.cpp b/builtin.cpp index cb06481f..0213f5cb 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1809,6 +1809,8 @@ int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstr bool shadows = true; woptind=0; + + wcstring_list_t wrap_targets; const struct woption long_options[] = { @@ -1818,6 +1820,7 @@ int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstr { L"on-process-exit", required_argument, 0, 'p' }, { L"on-variable", required_argument, 0, 'v' }, { L"on-event", required_argument, 0, 'e' }, + { L"wraps", required_argument, 0, 'w' }, { L"help", no_argument, 0, 'h' }, { L"argument-names", no_argument, 0, 'a' }, { L"no-scope-shadowing", no_argument, 0, 'S' }, @@ -1979,6 +1982,10 @@ int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstr case 'S': shadows = 0; break; + + case 'w': + wrap_targets.push_back(woptarg); + break; case 'h': builtin_print_help(parser, argv[0], stdout_buffer); @@ -2086,6 +2093,12 @@ int define_function(parser_t &parser, const wcstring_list_t &c_args, const wcstr d.definition = contents.c_str(); function_add(d, parser, definition_line_offset); + + // Handle wrap targets + for (size_t w=0; w < wrap_targets.size(); w++) + { + complete_add_wrapper(name, wrap_targets.at(w)); + } } return res; |