Hello everyone,

I am a user of the fish shell (http://fishshell.com/). However, the "system" 
function in Vim currently uses subshell syntax which is incompatible with fish. 
This forces fish users to set their shell to /bin/bash as a workaround. I have 
attached a patch that uses the fish syntax if Vim detects a user's shell as 
fish.

Note that this patch also refactors code that detects the name of a user's 
shell into a function "get_isolated_shell_name()" to avoid code duplication 
between option.c and ex_cmds.c.

I'm looking forward to a review.

Andy

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff -r 075eea398fff src/ex_cmds.c
--- a/src/ex_cmds.c	Fri May 02 15:46:14 2014 +0200
+++ b/src/ex_cmds.c	Mon May 05 22:46:12 2014 -0700
@@ -1551,8 +1551,14 @@
 {
     char_u	*buf;
     long_u	len;
-
-    len = (long_u)STRLEN(cmd) + 3;			/* "()" + NUL */
+    char_u	*shell_name;
+
+    /* Account for fish's different syntax for subshells */
+    shell_name = get_isolated_shell_name();
+    if (fnamecmp(shell_name, "fish") == 0)
+	len = (long_u)STRLEN(cmd) + 13;		/* "begin; " + "; end" + NUL */
+    else
+	len = (long_u)STRLEN(cmd) + 3;			/* "()" + NUL */
     if (itmp != NULL)
 	len += (long_u)STRLEN(itmp) + 9;		/* " { < " + " } " */
     if (otmp != NULL)
@@ -1567,7 +1573,10 @@
      * redirecting input and/or output.
      */
     if (itmp != NULL || otmp != NULL)
-	vim_snprintf((char *)buf, len, "(%s)", (char *)cmd);
+	if (fnamecmp(shell_name, "fish") == 0)
+	    vim_snprintf((char *)buf, len, "begin; %s; end", (char *)cmd);
+	else
+	    vim_snprintf((char *)buf, len, "(%s)", (char *)cmd);
     else
 	STRCPY(buf, cmd);
     if (itmp != NULL)
diff -r 075eea398fff src/misc1.c
--- a/src/misc1.c	Fri May 02 15:46:14 2014 +0200
+++ b/src/misc1.c	Mon May 05 22:46:12 2014 -0700
@@ -10896,3 +10896,40 @@
 {
     return (p_im && stuff_empty() && typebuf_typed());
 }
+
+/*
+ * Returns the isolated name of the shell:
+ * - Skip beyond any path.  E.g., "/usr/bin/csh -f" -> "csh -f".
+ * - Remove any argument.  E.g., "csh -f" -> "csh".
+ * But don't allow a space in the path, so that this works:
+ *   "/usr/bin/csh --rcfile ~/.cshrc"
+ * But don't do that for Windows, it's common to have a space in the path.
+ */
+    char_u *
+get_isolated_shell_name()
+{
+    char_u *p;
+#ifdef WIN3264
+    p = gettail(p_sh);
+    p = vim_strnsave(p, (int)(skiptowhite(p) - p));
+#else
+    p = skiptowhite(p_sh);
+    if (*p == NUL)
+    {
+	/* No white space, use the tail. */
+	p = vim_strsave(gettail(p_sh));
+    }
+    else
+    {
+	char_u  *p1, *p2;
+
+	/* Find the last path separator before the space. */
+	p1 = p_sh;
+	for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
+	    if (vim_ispathsep(*p2))
+		p1 = p2 + 1;
+	p = vim_strnsave(p1, (int)(p - p1));
+    }
+#endif
+    return p;
+}
diff -r 075eea398fff src/option.c
--- a/src/option.c	Fri May 02 15:46:14 2014 +0200
+++ b/src/option.c	Mon May 05 22:46:12 2014 -0700
@@ -3804,37 +3804,7 @@
     else
 	do_sp = !(options[idx_sp].flags & P_WAS_SET);
 #endif
-
-    /*
-     * Isolate the name of the shell:
-     * - Skip beyond any path.  E.g., "/usr/bin/csh -f" -> "csh -f".
-     * - Remove any argument.  E.g., "csh -f" -> "csh".
-     * But don't allow a space in the path, so that this works:
-     *   "/usr/bin/csh --rcfile ~/.cshrc"
-     * But don't do that for Windows, it's common to have a space in the path.
-     */
-#ifdef WIN3264
-    p = gettail(p_sh);
-    p = vim_strnsave(p, (int)(skiptowhite(p) - p));
-#else
-    p = skiptowhite(p_sh);
-    if (*p == NUL)
-    {
-	/* No white space, use the tail. */
-	p = vim_strsave(gettail(p_sh));
-    }
-    else
-    {
-	char_u  *p1, *p2;
-
-	/* Find the last path separator before the space. */
-	p1 = p_sh;
-	for (p2 = p_sh; p2 < p; mb_ptr_adv(p2))
-	    if (vim_ispathsep(*p2))
-		p1 = p2 + 1;
-	p = vim_strnsave(p1, (int)(p - p1));
-    }
-#endif
+    p = get_isolated_shell_name();
     if (p != NULL)
     {
 	/*
@@ -3875,6 +3845,7 @@
 		    || fnamecmp(p, "zsh") == 0
 		    || fnamecmp(p, "zsh-beta") == 0
 		    || fnamecmp(p, "bash") == 0
+                    || fnamecmp(p, "fish") == 0
 #  ifdef WIN3264
 		    || fnamecmp(p, "cmd") == 0
 		    || fnamecmp(p, "sh.exe") == 0
diff -r 075eea398fff src/proto/misc1.pro
--- a/src/proto/misc1.pro	Fri May 02 15:46:14 2014 +0200
+++ b/src/proto/misc1.pro	Mon May 05 22:46:12 2014 -0700
@@ -103,4 +103,5 @@
 char_u *get_cmd_output __ARGS((char_u *cmd, char_u *infile, int flags, int *ret_len));
 void FreeWild __ARGS((int count, char_u **files));
 int goto_im __ARGS((void));
+char_u *get_isolated_shell_name __ARGS((void));
 /* vim: set ft=c : */

Raspunde prin e-mail lui