aboutsummaryrefslogtreecommitdiffhomepage
path: root/builtin.h
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-08-15 18:14:36 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-08-15 18:14:36 -0700
commit06400b83b188156f31ed92216ec27122d29f88cd (patch)
tree2f9cec409aba50449638c8d4361b4dafe530f3ec /builtin.h
parentfe68d30be97853865b24ad5f5998d3e50769f860 (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.h')
-rw-r--r--builtin.h25
1 files changed, 19 insertions, 6 deletions
diff --git a/builtin.h b/builtin.h
index fb9a904d..3472995c 100644
--- a/builtin.h
+++ b/builtin.h
@@ -164,12 +164,25 @@ void builtin_pop_io(parser_t &parser);
wcstring builtin_get_desc(const wcstring &b);
-/**
- Slightly kludgy function used with 'complete -C' in order to make
- the commandline builtin operate on the string to complete instead
- of operating on whatever is to be completed.
-*/
-const wchar_t *builtin_complete_get_temporary_buffer();
+
+/** Support for setting and removing transient command lines.
+ This is used by 'complete -C' in order to make
+ the commandline builtin operate on the string to complete instead
+ of operating on whatever is to be completed. It's also used by
+ completion wrappers, to allow a command to appear as the command
+ being wrapped for the purposes of completion.
+
+ Instantiating an instance of builtin_commandline_scoped_transient_t
+ pushes the command as the new transient commandline. The destructor removes it.
+ It will assert if construction/destruction does not happen in a stack-like (LIFO) order.
+*/
+class builtin_commandline_scoped_transient_t
+{
+ size_t token;
+ public:
+ builtin_commandline_scoped_transient_t(const wcstring &cmd);
+ ~builtin_commandline_scoped_transient_t();
+};
/**