add -file-completion option to def command and document in README
This commit is contained in:
parent
f89636a182
commit
7c039585a4
|
@ -291,6 +291,8 @@ def can also takes some flags:
|
||||||
kak_paramN with N the parameter number
|
kak_paramN with N the parameter number
|
||||||
* *-shell-params*: pass parameters given to commands as positional parameters
|
* *-shell-params*: pass parameters given to commands as positional parameters
|
||||||
to any shell expansions used in the command.
|
to any shell expansions used in the command.
|
||||||
|
* *-file-completion*: try file completion on any parameter passed
|
||||||
|
to this command
|
||||||
* *-shell-completion*: following string is a shell command which takes
|
* *-shell-completion*: following string is a shell command which takes
|
||||||
parameters as positional params and output one
|
parameters as positional params and output one
|
||||||
completion candidate per line.
|
completion candidate per line.
|
||||||
|
|
|
@ -534,6 +534,7 @@ void define_command(const CommandParameters& params, Context& context)
|
||||||
{ { "env-params", false },
|
{ { "env-params", false },
|
||||||
{ "shell-params", false },
|
{ "shell-params", false },
|
||||||
{ "allow-override", false },
|
{ "allow-override", false },
|
||||||
|
{ "file-completion", false },
|
||||||
{ "shell-completion", true } });
|
{ "shell-completion", true } });
|
||||||
|
|
||||||
if (parser.positional_count() != 2)
|
if (parser.positional_count() != 2)
|
||||||
|
@ -570,10 +571,21 @@ void define_command(const CommandParameters& params, Context& context)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser.has_option("shell-completion"))
|
CommandCompleter completer;
|
||||||
|
if (parser.has_option("file-completion"))
|
||||||
|
{
|
||||||
|
completer = [](const Context& context, const CommandParameters& params,
|
||||||
|
size_t token_to_complete, CharCount pos_in_token)
|
||||||
|
{
|
||||||
|
const String& prefix = token_to_complete < params.size() ?
|
||||||
|
params[token_to_complete] : String();
|
||||||
|
return complete_filename(context, prefix, pos_in_token);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (parser.has_option("shell-completion"))
|
||||||
{
|
{
|
||||||
String shell_cmd = parser.option_value("shell-completion");
|
String shell_cmd = parser.option_value("shell-completion");
|
||||||
auto completer = [=](const Context& context, const CommandParameters& params,
|
completer = [=](const Context& context, const CommandParameters& params,
|
||||||
size_t token_to_complete, CharCount pos_in_token)
|
size_t token_to_complete, CharCount pos_in_token)
|
||||||
{
|
{
|
||||||
EnvVarMap vars = {
|
EnvVarMap vars = {
|
||||||
|
@ -583,10 +595,8 @@ void define_command(const CommandParameters& params, Context& context)
|
||||||
String output = ShellManager::instance().eval(shell_cmd, context, params, vars);
|
String output = ShellManager::instance().eval(shell_cmd, context, params, vars);
|
||||||
return split(output, '\n');
|
return split(output, '\n');
|
||||||
};
|
};
|
||||||
CommandManager::instance().register_command(cmd_name, cmd, completer);
|
|
||||||
}
|
}
|
||||||
else
|
CommandManager::instance().register_command(cmd_name, cmd, completer);
|
||||||
CommandManager::instance().register_command(cmd_name, cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void echo_message(const CommandParameters& params, Context& context)
|
void echo_message(const CommandParameters& params, Context& context)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user