0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.3071: shell options are not set properly for PowerShell

Problem:    Shell options are not set properly for PowerShell.
Solution:   Use better option defaults. (Mike Willams, closes #8459)
This commit is contained in:
Mike Williams
2021-06-28 20:53:58 +02:00
committed by Bram Moolenaar
parent ffec6dd16a
commit 127950241e
9 changed files with 206 additions and 49 deletions

View File

@@ -932,6 +932,27 @@ set_init_3(void)
options[idx_srr].def_val[VI_DEFAULT] = p_srr;
}
}
# ifdef MSWIN
// PowerShell 5.1/.NET outputs UTF-16 with BOM so re-encode to the
// current codepage
else if ( fnamecmp(p, "powershell") == 0
|| fnamecmp(p, "powershell.exe") == 0
)
{
# if defined(FEAT_QUICKFIX)
if (do_sp)
{
p_sp = (char_u *)"2>&1 | Out-File -Encoding default";
options[idx_sp].def_val[VI_DEFAULT] = p_sp;
}
# endif
if (do_srr)
{
p_srr = (char_u *)"2>&1 | Out-File -Encoding default";
options[idx_srr].def_val[VI_DEFAULT] = p_srr;
}
}
#endif
else
// Always use POSIX shell style redirection if we reach this
if ( fnamecmp(p, "sh") == 0
@@ -984,11 +1005,35 @@ set_init_3(void)
* Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
* 'shell' option.
* This is done after other initializations, where 'shell' might have been
* set, but only if they have not been set before. Default for p_shcf is
* "/c", for p_shq is "". For "sh" like shells it is changed here to
* "-c" and "\"". And for Win32 we need to set p_sxq instead.
* set, but only if they have not been set before.
* Default values depend on shell (cmd.exe is default shell):
*
* p_shcf p_sxq
* cmd.exe - "/c" "("
* powershell.exe - "-Command" "\""
* "sh" like shells - "-c" "\""
*
* For Win32 p_sxq is set instead of p_shq to include shell redirection.
*/
if (strstr((char *)gettail(p_sh), "sh") != NULL)
if (strstr((char *)gettail(p_sh), "powershell") != NULL)
{
int idx_opt;
idx_opt = findoption((char_u *)"shcf");
if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET))
{
p_shcf = (char_u*)"-Command";
options[idx_opt].def_val[VI_DEFAULT] = p_shcf;
}
idx_opt = findoption((char_u *)"sxq");
if (idx_opt >= 0 && !(options[idx_opt].flags & P_WAS_SET))
{
p_sxq = (char_u*)"\"";
options[idx_opt].def_val[VI_DEFAULT] = p_sxq;
}
}
else if (strstr((char *)gettail(p_sh), "sh") != NULL)
{
int idx3;