aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2014-08-17 23:08:11 -0400
committerJustin M. Keyes <justinkz@gmail.com>2014-08-17 23:08:11 -0400
commitd067ad66ac2b6eb22eef3bfb7efa0007b7af9e5b (patch)
tree2514ad0e09eaacd59641974c823f194d3abd3140 /src/nvim/ex_cmds.c
parent16a04bae0a91e00d120b6fdd8e24b620b9859c87 (diff)
parentd2988e12fe577bcb6e91be359049b1355fa51aed (diff)
downloadrneovim-d067ad66ac2b6eb22eef3bfb7efa0007b7af9e5b.tar.gz
rneovim-d067ad66ac2b6eb22eef3bfb7efa0007b7af9e5b.tar.bz2
rneovim-d067ad66ac2b6eb22eef3bfb7efa0007b7af9e5b.zip
Merge pull request #977 from splinterofchaos/fish
vim-patch:7.4.276
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r--src/nvim/ex_cmds.c68
1 files changed, 37 insertions, 31 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 0a26026d7b..48e75190aa 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1307,52 +1307,58 @@ do_shell (
apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf);
}
-/*
- * Create a shell command from a command string, input redirection file and
- * output redirection file.
- * Returns an allocated string with the shell command.
- */
-char_u *
-make_filter_cmd (
- char_u *cmd, /* command */
- char_u *itmp, /* NULL or name of input file */
- char_u *otmp /* NULL or name of output file */
-)
+/// Create a shell command from a command string, input redirection file and
+/// output redirection file.
+///
+/// @param cmd Command to execute.
+/// @param itmp NULL or the input file.
+/// @param otmp NULL or the output file.
+/// @returns an allocated string with the shell command.
+char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp)
{
- size_t len = STRLEN(cmd) + 3; /* "()" + NUL */
+ bool is_fish_shell =
+#if defined(UNIX)
+ STRNCMP(invocation_path_tail(p_sh, NULL), "fish", 4) == 0;
+#else
+ false;
+#endif
+
+ size_t len = STRLEN(cmd) + 1; // At least enough space for cmd + NULL.
+
+ len += is_fish_shell ? sizeof("begin; ""; end") - 1
+ : sizeof("("")") - 1;
+
if (itmp != NULL)
- len += STRLEN(itmp) + 9; /* " { < " + " } " */
+ len += STRLEN(itmp) + sizeof(" { "" < "" } ") - 1;
if (otmp != NULL)
- len += STRLEN(otmp) + STRLEN(p_srr) + 2; /* " " */
+ len += STRLEN(otmp) + STRLEN(p_srr) + 2; // two extra spaces (" "),
char_u *buf = xmalloc(len);
#if defined(UNIX)
- /*
- * Put braces around the command (for concatenated commands) when
- * redirecting input and/or output.
- */
- if (itmp != NULL || otmp != NULL)
- vim_snprintf((char *)buf, len, "(%s)", (char *)cmd);
- else
+ // Put delimiters around the command (for concatenated commands) when
+ // redirecting input and/or output.
+ if (itmp != NULL || otmp != NULL) {
+ char *fmt = is_fish_shell ? "begin; %s; end"
+ : "(%s)";
+ vim_snprintf((char *)buf, len, fmt, (char *)cmd);
+ } else {
STRCPY(buf, cmd);
+ }
+
if (itmp != NULL) {
STRCAT(buf, " < ");
STRCAT(buf, itmp);
}
#else
- /*
- * for shells that don't understand braces around commands, at least allow
- * the use of commands in a pipe.
- */
+ // For shells that don't understand braces around commands, at least allow
+ // the use of commands in a pipe.
STRCPY(buf, cmd);
if (itmp != NULL) {
char_u *p;
- /*
- * If there is a pipe, we have to put the '<' in front of it.
- * Don't do this when 'shellquote' is not empty, otherwise the
- * redirection would be inside the quotes.
- */
+ // If there is a pipe, we have to put the '<' in front of it.
+ // Don't do this when 'shellquote' is not empty, otherwise the
+ // redirection would be inside the quotes.
if (*p_shq == NUL) {
p = vim_strchr(buf, '|');
if (p != NULL)
@@ -1363,7 +1369,7 @@ make_filter_cmd (
if (*p_shq == NUL) {
p = vim_strchr(cmd, '|');
if (p != NULL) {
- STRCAT(buf, " "); /* insert a space before the '|' for DOS */
+ STRCAT(buf, " "); // Insert a space before the '|' for DOS
STRCAT(buf, p);
}
}