summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-06-23 09:58:31 +1000
committerMaxime Coste <mawww@kakoune.org>2019-06-23 12:04:21 +1000
commita9e778fcc7f06a27f2d06da225f08110c9e2dca9 (patch)
treefddb0d17626b07bcc0e8909da64eb99ad441b78e /src
parent95da8cbc8fc1b7d87e89291bf40c0855d41e3108 (diff)
Add support for `echo -quoting (raw|kakoune|shell)` switch
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc9
-rw-r--r--src/string_utils.hh10
2 files changed, 18 insertions, 1 deletions
diff --git a/src/commands.cc b/src/commands.cc
index c03358ce..75ccecc2 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -1245,6 +1245,7 @@ const CommandDesc echo_cmd = {
"echo <params>...: display given parameters in the status line",
ParameterDesc{
{ { "markup", { false, "parse markup" } },
+ { "quoting", { true, "quote each argument separately using the given style (raw|kakoune|shell)" } },
{ "to-file", { true, "echo contents to given filename" } },
{ "debug", { false, "write to debug buffer instead of status line" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart
@@ -1254,7 +1255,13 @@ const CommandDesc echo_cmd = {
CommandCompleter{},
[](const ParametersParser& parser, Context& context, const ShellContext&)
{
- String message = join(parser, ' ', false);
+ String message;
+ if (auto quoting = parser.get_switch("quoting"))
+ message = join(parser | transform(quoter(option_from_string(Meta::Type<Quoting>{}, *quoting))),
+ ' ', false);
+ else
+ message = join(parser, ' ', false);
+
if (auto filename = parser.get_switch("to-file"))
return write_to_file(*filename, message);
diff --git a/src/string_utils.hh b/src/string_utils.hh
index 224dffc2..928070d3 100644
--- a/src/string_utils.hh
+++ b/src/string_utils.hh
@@ -2,6 +2,7 @@
#define string_utils_hh_INCLUDED
#include "string.hh"
+#include "enum.hh"
#include "vector.hh"
#include "optional.hh"
@@ -143,6 +144,15 @@ enum class Quoting
Shell
};
+constexpr auto enum_desc(Meta::Type<Quoting>)
+{
+ return make_array<EnumDesc<Quoting>, 3>({
+ { Quoting::Raw, "raw" },
+ { Quoting::Kakoune, "kakoune" },
+ { Quoting::Shell, "shell" }
+ });
+}
+
inline auto quoter(Quoting quoting)
{
switch (quoting)