0
0
mirror of https://github.com/vim/vim.git synced 2025-10-08 06:04:08 -04:00

patch 8.2.3079: Powershell core not supported by default

Problem:    Powershell core not supported by default.
Solution:   Set option defaults for "pwsh". (Mike Williams, closes #8481)
This commit is contained in:
Mike Williams
2021-06-30 20:56:00 +02:00
committed by Bram Moolenaar
parent 834193afd7
commit a3d1b29bd3
10 changed files with 118 additions and 52 deletions

View File

@@ -5222,6 +5222,7 @@ vim_tempname(
WCHAR *chartab = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char_u *retval;
char_u *p;
char_u *shname;
long i;
wcscpy(itmp, L"");
@@ -5247,8 +5248,10 @@ vim_tempname(
// "sh". NOTE: This also checks 'shellcmdflag' to help those people who
// didn't set 'shellslash' but only if not using PowerShell.
retval = utf16_to_enc(itmp, NULL);
if ((strstr((char *)gettail(p_sh), "powershell") == NULL
&& *p_shcf == '-') || p_ssl)
shname = gettail(p_sh);
if ((*p_shcf == '-' && !(strstr((char *)shname, "powershell") != NULL
|| strstr((char *)shname, "pwsh") != NULL ))
|| p_ssl)
for (p = retval; *p; ++p)
if (*p == '\\')
*p = '/';

View File

@@ -1414,8 +1414,9 @@ vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
char_u *escaped_string;
int l;
int csh_like;
# ifdef MSWIN
char_u *shname;
int powershell;
# ifdef MSWIN
int double_quotes;
# endif
@@ -1425,9 +1426,12 @@ 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();
// PowerShell uses it's own version for quoting single quotes
shname = gettail(p_sh);
powershell = strstr((char *)shname, "pwsh") != NULL;
# ifdef MSWIN
// PowerShell only accepts single quotes so override p_ssl.
powershell = strstr((char *)gettail(p_sh), "powershell") != NULL;
powershell = powershell || strstr((char *)shname, "powershell") != NULL;
// PowerShell only accepts single quotes so override shellslash.
double_quotes = !powershell && !p_ssl;
# endif
@@ -1445,11 +1449,9 @@ vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
# endif
if (*p == '\'')
{
# ifdef MSWIN
if (powershell)
length +=2; // ' => ''
else
# endif
length += 3; // ' => '\''
}
if ((*p == '\n' && (csh_like || do_newline))
@@ -1497,14 +1499,12 @@ vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
# endif
if (*p == '\'')
{
# ifdef MSWIN
if (powershell)
{
*d++ = '\'';
*d++ = '\'';
}
else
# endif
{
*d++ = '\'';
*d++ = '\\';

View File

@@ -933,8 +933,8 @@ set_init_3(void)
}
}
# ifdef MSWIN
// PowerShell 5.1/.NET outputs UTF-16 with BOM so re-encode to the
// current codepage
// Windows PowerShell output is UTF-16 with BOM so re-encode to the
// current codepage.
else if ( fnamecmp(p, "powershell") == 0
|| fnamecmp(p, "powershell.exe") == 0
)
@@ -965,6 +965,7 @@ set_init_3(void)
|| fnamecmp(p, "fish") == 0
|| fnamecmp(p, "ash") == 0
|| fnamecmp(p, "dash") == 0
|| fnamecmp(p, "pwsh") == 0
# ifdef MSWIN
|| fnamecmp(p, "cmd") == 0
|| fnamecmp(p, "sh.exe") == 0
@@ -976,6 +977,7 @@ set_init_3(void)
|| fnamecmp(p, "bash.exe") == 0
|| fnamecmp(p, "cmd.exe") == 0
|| fnamecmp(p, "dash.exe") == 0
|| fnamecmp(p, "pwsh.exe") == 0
# endif
)
{
@@ -985,7 +987,10 @@ set_init_3(void)
# ifdef MSWIN
p_sp = (char_u *)">%s 2>&1";
# else
p_sp = (char_u *)"2>&1| tee";
if (fnamecmp(p, "pwsh") == 0)
p_sp = (char_u *)">%s 2>&1";
else
p_sp = (char_u *)"2>&1| tee";
# endif
options[idx_sp].def_val[VI_DEFAULT] = p_sp;
}
@@ -1011,6 +1016,7 @@ set_init_3(void)
* p_shcf p_sxq
* cmd.exe - "/c" "("
* powershell.exe - "-Command" "\""
* pwsh.exe - "-c" "\""
* "sh" like shells - "-c" "\""
*
* For Win32 p_sxq is set instead of p_shq to include shell redirection.

View File

@@ -2135,6 +2135,7 @@ executable_exists(char *name, char_u **path, int use_path, int use_pathext)
char_u *pathbuf = NULL;
char_u *pathext = NULL;
char_u *pathextbuf = NULL;
char_u *shname = NULL;
int noext = FALSE;
int retval = FALSE;
@@ -2142,8 +2143,10 @@ executable_exists(char *name, char_u **path, int use_path, int use_pathext)
return FALSE;
// Using the name directly when a Unix-shell like 'shell'.
if (strstr((char *)gettail(p_sh), "powershell") == NULL
&& strstr((char *)gettail(p_sh), "sh") != NULL)
shname = gettail(p_sh);
if (strstr((char *)shname, "sh") != NULL &&
!(strstr((char *)shname, "powershell") != NULL
|| strstr((char *)shname, "pwsh") != NULL))
noext = TRUE;
if (use_pathext)

View File

@@ -19,7 +19,8 @@ func Test_shell_options()
\ ['ash', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
\ ['dash', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''],
\ ['csh', '-c', '|& tee', '', '>&', '', ''],
\ ['tcsh', '-c', '|& tee', '', '>&', '', '']]
\ ['tcsh', '-c', '|& tee', '', '>&', '', ''],
\ ['pwsh', '-c', '>%s 2>&1', '', '>%s 2>&1', '', '']]
endif
if has('win32')
let shells += [['cmd', '/c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', ''],
@@ -28,6 +29,8 @@ func Test_shell_options()
\ '', '2>&1 | Out-File -Encoding default', '"&|<>()@^', '"'],
\ ['powershell', '-Command', '2>&1 | Out-File -Encoding default', '',
\ '2>&1 | Out-File -Encoding default', '"&|<>()@^', '"'],
\ ['pwsh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
\ ['pwsh', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
\ ['sh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
\ ['ksh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
\ ['mksh.exe', '-c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '"'],
@@ -61,6 +64,7 @@ func Test_shell_options()
let str1 = "'cmd \"arg1\" '\\''arg2'\\'' \\!%#'"
let str2 = "'cmd \"arg1\" '\\''arg2'\\'' \\\\!\\%\\#'"
elseif e[0] =~# '.*powershell$' || e[0] =~# '.*powershell.exe$'
\ || e[0] =~# '.*pwsh$' || e[0] =~# '.*pwsh.exe$'
let str1 = "'cmd \"arg1\" ''arg2'' !%#'"
let str2 = "'cmd \"arg1\" ''arg2'' \\!\\%\\#'"
else
@@ -76,9 +80,14 @@ func Test_shell_options()
let [&shellcmdflag, &shellpipe, &shellquote, &shellredir,
\ &shellxescape, &shellxquote] = e[1:6]
new
r !echo hello
call assert_equal('hello', substitute(getline(2), '\W', '', 'g'), e[0])
bwipe!
try
r !echo hello
call assert_equal('hello', substitute(getline(2), '\W', '', 'g'), e[0])
catch
call assert_report('Failed to run shell command, shell: ' .. e[0])
finally
bwipe!
endtry
endif
endfor
set shell& shellcmdflag& shellpipe& shellquote&
@@ -149,6 +158,8 @@ func Test_shellslash()
" ".*\\\\[^\\\\]*$"
let shells = [['cmd', '/c', '\\', '/'],
\ ['powershell', '-Command', '\\', '/'],
\ ['pwsh', '-Command', '\\', '/'],
\ ['pwsh', '-c', '\\', '/'],
\ ['sh', '-c', '/', '/']]
for e in shells
exe 'set shell=' .. e[0] .. ' | set shellcmdflag=' .. e[1]

View File

@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3079,
/**/
3078,
/**/