aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_docmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r--src/nvim/ex_docmd.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index c7cb875b88..1234f8e888 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -9627,26 +9627,38 @@ static void ex_folddo(exarg_T *eap)
static void ex_terminal(exarg_T *eap)
{
- char *name = (char *)p_sh; // Default to 'shell' if {cmd} is not given.
- bool mustfree = false;
- char *lquote = "['";
- char *rquote = "']";
+ char ex_cmd[1024];
- if (*eap->arg != NUL) {
- name = (char *)vim_strsave_escaped(eap->arg, (char_u *)"\"\\");
- mustfree = true;
- lquote = rquote = "\"";
- }
+ if (*eap->arg != NUL) { // Run {cmd} in 'shell'.
+ char *name = (char *)vim_strsave_escaped(eap->arg, (char_u *)"\"\\");
+ snprintf(ex_cmd, sizeof(ex_cmd),
+ ":enew%s | call termopen(\"%s\") | startinsert",
+ eap->forceit ? "!" : "", name);
+ xfree(name);
+ } else { // No {cmd}: run the job with tokenized 'shell'.
+ if (*p_sh == NUL) {
+ EMSG(_(e_shellempty));
+ return;
+ }
- char ex_cmd[512];
- snprintf(ex_cmd, sizeof(ex_cmd),
- ":enew%s | call termopen(%s%s%s) | startinsert",
- eap->forceit==TRUE ? "!" : "", lquote, name, rquote);
- do_cmdline_cmd(ex_cmd);
+ char **argv = shell_build_argv(NULL, NULL);
+ char **p = argv;
+ char tempstring[512];
+ char shell_argv[512] = { 0 };
- if (mustfree) {
- xfree(name);
+ while (*p != NULL) {
+ snprintf(tempstring, sizeof(tempstring), ",\"%s\"", *p);
+ xstrlcat(shell_argv, tempstring, sizeof(shell_argv));
+ p++;
+ }
+ shell_free_argv(argv);
+
+ snprintf(ex_cmd, sizeof(ex_cmd),
+ ":enew%s | call termopen([%s]) | startinsert",
+ eap->forceit ? "!" : "", shell_argv + 1);
}
+
+ do_cmdline_cmd(ex_cmd);
}
/// Checks if `cmd` is "previewable" (i.e. supported by 'inccommand').