diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-03-24 14:01:59 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-03-24 14:01:59 +0000 |
| commit | 840b7658fdf46c60feeee3335ab55068e24cc27d (patch) | |
| tree | 5d101a0a4fdc9ad0b74aaa4828042e8840a76219 /src | |
| parent | b0d72ebce00a23b19db179310e675a98189340c2 (diff) | |
Add an alternative -shell-candidates shell completion support
-shell-candidates use a shell script that returns all the candidates
and then sort them using Kakoune ranked matches system instead of
delegating the whole completion to the shell script (as shell-completion does)
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/commands.cc b/src/commands.cc index a483573b..e6f0af0f 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -827,6 +827,36 @@ void define_command(const ParametersParser& parser, Context& context, const Shel return Completions{ 0_byte, pos_in_token, split(output, '\n', 0) }; }; } + else if (auto shell_cmd_opt = parser.get_switch("shell-candidates")) + { + String shell_cmd = shell_cmd_opt->str(); + Vector<String> candidates; + int token = -1; + completer = [shell_cmd, candidates, token]( + const Context& context, CompletionFlags flags, CommandParameters params, + size_t token_to_complete, ByteCount pos_in_token) mutable + { + if (token != token_to_complete) + { + if (flags == CompletionFlags::Fast) // no shell on fast completion + return Completions{}; + + ShellContext shell_context{ + params, + { { "token_to_complete", to_string(token_to_complete) } } + }; + String output = ShellManager::instance().eval(shell_cmd, context, {}, + ShellManager::Flags::WaitForStdout, + shell_context).first; + candidates = split(output, '\n', 0); + token = token_to_complete; + } + + return token == token_to_complete ? + Completions{ 0_byte, pos_in_token, complete(params[token_to_complete], pos_in_token, candidates) } + : Completions{}; + }; + } else if (parser.get_switch("command-completion")) { completer = [](const Context& context, CompletionFlags flags, @@ -857,7 +887,8 @@ const CommandDesc define_command_cmd = { { "client-completion", { false, "complete parameters using client name completion" } }, { "buffer-completion", { false, "complete parameters using buffer name completion" } }, { "command-completion", { false, "complete parameters using kakoune command completion" } }, - { "shell-completion", { true, "complete the parameters using the given shell-script" } } }, + { "shell-completion", { true, "complete the parameters using the given shell-script" } }, + { "shell-candidates", { true, "get the parameter candidates using the given shell-script" } } }, ParameterDesc::Flags::None, 2, 2 }, |
