summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/pages/commands.asciidoc14
-rw-r--r--src/commands.cc9
-rw-r--r--src/string_utils.hh10
3 files changed, 32 insertions, 1 deletions
diff --git a/doc/pages/commands.asciidoc b/doc/pages/commands.asciidoc
index ebaafaea..2ef0f3a9 100644
--- a/doc/pages/commands.asciidoc
+++ b/doc/pages/commands.asciidoc
@@ -210,6 +210,20 @@ of the file onto the filesystem
write the given text to the given file on the host
filesystem.
+ *-quoting* <quoting>:::
+ define how each arguments are quoted in echo output:
+
+ - *raw* (default)::::
+ just join each argument with a space
+
+ - *kakoune*::::
+ also wrap each argument in single quotes, doubling-up
+ embedded quotes.
+
+ - *shell*::::
+ also wrap each arguments in single quotes and escape
+ embedded quotes in a shell compatible way.
+
*set-face* <scope> <name> <facespec>::
*alias* face +
define a face in *scope*
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)