Add -to-shell-script echo switch

This feature simplifies various small use cases and is a good
companion to the existing -to-file switch.
This commit is contained in:
Maxime Coste 2022-11-04 16:40:07 +11:00
parent 98b84f2b05
commit ca6a701b80
2 changed files with 10 additions and 4 deletions

View File

@ -260,6 +260,10 @@ of the file onto the filesystem
write the given text to the given file on the host write the given text to the given file on the host
filesystem. filesystem.
*-to-shell-script* <script>:::
execute the given shell script with the given text
written to its standard input
*-quoting* <quoting>::: *-quoting* <quoting>:::
define how arguments are quoted in echo output: define how arguments are quoted in echo output:

View File

@ -1427,13 +1427,14 @@ const CommandDesc echo_cmd = {
{ { "markup", { false, "parse markup" } }, { { "markup", { false, "parse markup" } },
{ "quoting", { true, "quote each argument separately using the given style (raw|kakoune|shell)" } }, { "quoting", { true, "quote each argument separately using the given style (raw|kakoune|shell)" } },
{ "to-file", { true, "echo contents to given filename" } }, { "to-file", { true, "echo contents to given filename" } },
{ "to-shell-script", { true, "pipe contents to given shell script" } },
{ "debug", { false, "write to debug buffer instead of status line" } } }, { "debug", { false, "write to debug buffer instead of status line" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart ParameterDesc::Flags::SwitchesOnlyAtStart
}, },
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, CommandCompleter{},
[](const ParametersParser& parser, Context& context, const ShellContext&) [](const ParametersParser& parser, Context& context, const ShellContext& shell_context)
{ {
String message; String message;
if (auto quoting = parser.get_switch("quoting")) if (auto quoting = parser.get_switch("quoting"))
@ -1443,9 +1444,10 @@ const CommandDesc echo_cmd = {
message = join(parser, ' ', false); message = join(parser, ' ', false);
if (auto filename = parser.get_switch("to-file")) if (auto filename = parser.get_switch("to-file"))
return write_to_file(*filename, message); write_to_file(*filename, message);
else if (auto command = parser.get_switch("to-shell-script"))
if (parser.get_switch("debug")) ShellManager::instance().eval(*command, context, message, ShellManager::Flags::None, shell_context);
else if (parser.get_switch("debug"))
write_to_debug_buffer(message); write_to_debug_buffer(message);
else if (parser.get_switch("markup")) else if (parser.get_switch("markup"))
context.print_status(parse_display_line(message, context.faces())); context.print_status(parse_display_line(message, context.faces()));