diff options
author | Mike Williams <mikew@globalgraphics.com> | 2021-06-30 20:56:00 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-06-30 20:56:00 +0200 |
commit | a3d1b29bd36487167c98b3cefa30f06c529e412d (patch) | |
tree | c2f313a89feb1b97cdd945ce904d258b518e9cae /src | |
parent | 834193afd7195bc96026d2aed696d64f8075cd35 (diff) |
patch 8.2.3079: Powershell core not supported by defaultv8.2.3079
Problem: Powershell core not supported by default.
Solution: Set option defaults for "pwsh". (Mike Williams, closes #8481)
Diffstat (limited to 'src')
-rw-r--r-- | src/fileio.c | 7 | ||||
-rw-r--r-- | src/misc2.c | 14 | ||||
-rw-r--r-- | src/option.c | 12 | ||||
-rw-r--r-- | src/os_win32.c | 7 | ||||
-rw-r--r-- | src/testdir/test_shell.vim | 19 | ||||
-rw-r--r-- | src/version.c | 2 |
6 files changed, 43 insertions, 18 deletions
diff --git a/src/fileio.c b/src/fileio.c index 55012bfcbd..bd4038c36a 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -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 = '/'; diff --git a/src/misc2.c b/src/misc2.c index 6bbfbd775c..ead1e63555 100644 --- a/src/misc2.c +++ b/src/misc2.c @@ -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++ = '\\'; diff --git a/src/option.c b/src/option.c index 5fc059e29d..ae303106ad 100644 --- a/src/option.c +++ b/src/option.c @@ -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. diff --git a/src/os_win32.c b/src/os_win32.c index 1a005c9d53..eff2269f8c 100644 --- a/src/os_win32.c +++ b/src/os_win32.c @@ -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) diff --git a/src/testdir/test_shell.vim b/src/testdir/test_shell.vim index 753a0d5249..f5a3e98997 100644 --- a/src/testdir/test_shell.vim +++ b/src/testdir/test_shell.vim @@ -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] diff --git a/src/version.c b/src/version.c index 3c626bb670..e9ad71b816 100644 --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3079, +/**/ 3078, /**/ 3077, |