mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.3385: escaping for fish shell does not work properly
Problem: Escaping for fish shell does not work properly. Solution: Insert a backslash before a backslash. (Jason Cox, closes #8810)
This commit is contained in:
committed by
Bram Moolenaar
parent
9dcd349ca8
commit
6e82351130
@@ -124,6 +124,15 @@ csh_like_shell(void)
|
||||
return (strstr((char *)gettail(p_sh), "csh") != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE when 'shell' has "fish" in the tail.
|
||||
*/
|
||||
int
|
||||
fish_like_shell(void)
|
||||
{
|
||||
return (strstr((char *)gettail(p_sh), "fish") != NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Escape "string" for use as a shell argument with system().
|
||||
* This uses single quotes, except when we know we need to use double quotes
|
||||
@@ -145,6 +154,7 @@ vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
|
||||
char_u *escaped_string;
|
||||
int l;
|
||||
int csh_like;
|
||||
int fish_like;
|
||||
char_u *shname;
|
||||
int powershell;
|
||||
# ifdef MSWIN
|
||||
@@ -157,6 +167,10 @@ vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
|
||||
// Csh also needs to have "\n" escaped twice when do_special is set.
|
||||
csh_like = csh_like_shell();
|
||||
|
||||
// Fish shell uses '\' as an escape character within single quotes, so '\'
|
||||
// itself must be escaped to get a literal '\'.
|
||||
fish_like = fish_like_shell();
|
||||
|
||||
// PowerShell uses it's own version for quoting single quotes
|
||||
shname = gettail(p_sh);
|
||||
powershell = strstr((char *)shname, "pwsh") != NULL;
|
||||
@@ -197,6 +211,8 @@ vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
|
||||
++length; // insert backslash
|
||||
p += l - 1;
|
||||
}
|
||||
if (*p == '\\' && fish_like)
|
||||
++length; // insert backslash
|
||||
}
|
||||
|
||||
// Allocate memory for the result and fill it.
|
||||
@@ -261,6 +277,11 @@ vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
|
||||
*d++ = *p++;
|
||||
continue;
|
||||
}
|
||||
if (*p == '\\' && fish_like)
|
||||
{
|
||||
*d++ = '\\';
|
||||
*d++ = *p++;
|
||||
}
|
||||
|
||||
MB_COPY_CHAR(p, d);
|
||||
}
|
||||
|
Reference in New Issue
Block a user