aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/shell.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-09-21 09:20:04 +0200
committerGitHub <noreply@github.com>2018-09-21 09:20:04 +0200
commitecdd2df88ab52ed6e39057e2a8fb9eabfbb90bd5 (patch)
treea6072625d7c97b943c4ed5cbfe3d258bd111c23f /src/nvim/os/shell.c
parentad6bbe44683cf936ec2268ee89e8e1c22f538ecc (diff)
downloadrneovim-ecdd2df88ab52ed6e39057e2a8fb9eabfbb90bd5.tar.gz
rneovim-ecdd2df88ab52ed6e39057e2a8fb9eabfbb90bd5.tar.bz2
rneovim-ecdd2df88ab52ed6e39057e2a8fb9eabfbb90bd5.zip
shell/logging: Fix E730 with verbose system({List}) #9009
ref https://github.com/neovim/neovim/issues/9001#issuecomment-421843790 Steps to reproduce: :set verbose=9 :call system(['echo']) E730: using List as a String
Diffstat (limited to 'src/nvim/os/shell.c')
-rw-r--r--src/nvim/os/shell.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index aa4e7d307b..19d199f4d5 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -80,21 +80,53 @@ char **shell_build_argv(const char *cmd, const char *extra_args)
void shell_free_argv(char **argv)
{
char **p = argv;
-
if (p == NULL) {
// Nothing was allocated, return
return;
}
-
while (*p != NULL) {
// Free each argument
xfree(*p);
p++;
}
-
xfree(argv);
}
+/// Joins shell arguments from `argv` into a new string.
+/// If the result is too long it is truncated with ellipsis ("...").
+///
+/// @returns[allocated] `argv` joined to a string.
+char *shell_argv_to_str(char **const argv)
+ FUNC_ATTR_NONNULL_ALL
+{
+ size_t n = 0;
+ char **p = argv;
+ char *rv = xcalloc(256, sizeof(*rv));
+ const size_t maxsize = (256 * sizeof(*rv));
+ if (*p == NULL) {
+ return rv;
+ }
+ while (*p != NULL) {
+ xstrlcat(rv, "'", maxsize);
+ xstrlcat(rv, *p, maxsize);
+ n = xstrlcat(rv, "' ", maxsize);
+ if (n >= maxsize) {
+ break;
+ }
+ p++;
+ }
+ if (n < maxsize) {
+ rv[n - 1] = '\0';
+ } else {
+ // Command too long, show ellipsis: "/bin/bash 'foo' 'bar'..."
+ rv[maxsize - 4] = '.';
+ rv[maxsize - 3] = '.';
+ rv[maxsize - 2] = '.';
+ rv[maxsize - 1] = '\0';
+ }
+ return rv;
+}
+
/// Calls the user-configured 'shell' (p_sh) for running a command or wildcard
/// expansion.
///