Patch 8.2.3071
Problem:    Shell options are not set properly for PowerShell.
Solution:   Use better option defaults. (Mike Willams, closes #8459)
Files:      runtime/doc/eval.txt, runtime/doc/options.txt,
            runtime/doc/os_dos.txt, src/fileio.c, src/misc2.c, src/option.c,
            src/os_win32.c, src/testdir/test_shell.vim


*** ../vim-8.2.3070/runtime/doc/eval.txt        2021-06-23 20:46:46.910256869 
+0200
--- runtime/doc/eval.txt        2021-06-28 20:42:51.932592764 +0200
***************
*** 9848,9856 ****
  
  shellescape({string} [, {special}])                   *shellescape()*
                Escape {string} for use as a shell command argument.
!               On MS-Windows, when 'shellslash' is not set, it will enclose
!               {string} in double quotes and double all double quotes within
!               {string}.
                Otherwise it will enclose {string} in single quotes and
                replace all "'" with "'\''".
  
--- 9888,9898 ----
  
  shellescape({string} [, {special}])                   *shellescape()*
                Escape {string} for use as a shell command argument.
!               On MS-Windows, when the 'shell' contains powershell then it
!               will enclose {string} in single quotes and will double up all
!               internal single quotes.  With other values for 'shell' when
!               'shellslash' is not set, it will enclose {string} in double
!               quotes and double all double quotes within {string}.
                Otherwise it will enclose {string} in single quotes and
                replace all "'" with "'\''".
  
***************
*** 11010,11016 ****
                        :exe "redir > " . tmpfile
  <             For Unix, the file will be in a private directory |tempfile|.
                For MS-Windows forward slashes are used when the 'shellslash'
!               option is set or when 'shellcmdflag' starts with '-'.
  
  
  term_ functions are documented here: |terminal-function-details|
--- 11052,11059 ----
                        :exe "redir > " . tmpfile
  <             For Unix, the file will be in a private directory |tempfile|.
                For MS-Windows forward slashes are used when the 'shellslash'
!               option is set or when 'shellcmdflag' starts with '-' except
!               when when 'shell' contains powershell.
  
  
  term_ functions are documented here: |terminal-function-details|
***************
*** 13224,13231 ****
                        file names.  The |fnameescape()| function can be used
                        for Vim commands, |shellescape()| for |:!| commands.
                        Examples: >
!               :execute "e " . fnameescape(filename)
!               :execute "!ls " . shellescape(filename, 1)
  <
                        Note: The executed string may be any command-line, but
                        starting or ending "if", "while" and "for" does not
--- 13268,13275 ----
                        file names.  The |fnameescape()| function can be used
                        for Vim commands, |shellescape()| for |:!| commands.
                        Examples: >
!               :execute "e " .. fnameescape(filename)
!               :execute "!ls " .. shellescape(filename, 1)
  <
                        Note: The executed string may be any command-line, but
                        starting or ending "if", "while" and "for" does not
*** ../vim-8.2.3070/runtime/doc/options.txt     2021-06-20 14:01:25.976924630 
+0200
--- runtime/doc/options.txt     2021-06-28 20:42:51.932592764 +0200
***************
*** 6587,6609 ****
  
                                                *'shellcmdflag'* *'shcf'*
  'shellcmdflag' 'shcf' string  (default: "-c";
!                                Win32, when 'shell' does not contain "sh"
                                 somewhere: "/c")
                        global
        Flag passed to the shell to execute "!" and ":!" commands; e.g.,
!       "bash.exe -c ls" or "cmd.exe /c dir".  For MS-Windows, the default is
!       set according to the value of 'shell', to reduce the need to set this
!       option by the user.
        On Unix it can have more than one flag.  Each white space separated
        part is passed as an argument to the shell command.
        See |option-backslash| about including spaces and backslashes.
!       Also see |dos-shell| for MS-Windows.
        This option cannot be set from a |modeline| or in the |sandbox|, for
        security reasons.
  
                                                *'shellpipe'* *'sp'*
! 'shellpipe' 'sp'      string  (default ">", ">%s 2>&1", "| tee", "|& tee" or
!                                "2>&1| tee")
                        global
                        {not available when compiled without the |+quickfix|
                        feature}
--- 6594,6618 ----
  
                                                *'shellcmdflag'* *'shcf'*
  'shellcmdflag' 'shcf' string  (default: "-c";
!                                Win32, when 'shell' contains "powershell":
!                                "-Command", or when it does not contain "sh"
                                 somewhere: "/c")
                        global
        Flag passed to the shell to execute "!" and ":!" commands; e.g.,
!       "bash.exe -c ls", "powershell.exe -Command dir", or "cmd.exe /c dir".
!       For MS-Windows, the default is set according to the value of 'shell',
!       to reduce the need to set this option by the user.
        On Unix it can have more than one flag.  Each white space separated
        part is passed as an argument to the shell command.
        See |option-backslash| about including spaces and backslashes.
!       Also see |dos-shell| and |dos-powershell| for MS-Windows.
        This option cannot be set from a |modeline| or in the |sandbox|, for
        security reasons.
  
                                                *'shellpipe'* *'sp'*
! 'shellpipe' 'sp'      string  (default ">", ">%s 2>&1", "| tee", "|& tee"
!                                "2>&1| tee", or
!                                "2>&1 | Out-File -Encoding default")
                        global
                        {not available when compiled without the |+quickfix|
                        feature}
***************
*** 6613,6621 ****
        The name of the temporary file can be represented by "%s" if necessary
        (the file name is appended automatically if no %s appears in the value
        of this option).
!       For the Amiga the default is ">".  For MS-Windows the default is
!       ">%s 2>&1".  The output is directly saved in a file and not echoed to
!       the screen.
        For Unix the default is "| tee".  The stdout of the compiler is saved
        in a file and echoed to the screen.  If the 'shell' option is "csh" or
        "tcsh" after initializations, the default becomes "|& tee".  If the
--- 6622,6631 ----
        The name of the temporary file can be represented by "%s" if necessary
        (the file name is appended automatically if no %s appears in the value
        of this option).
!       For the Amiga the default is ">".  For MS-Windows using powershell the
!       default is "2>&1 | Out-File -Encoding default", otherwise the default
!       is ">%s 2>&1".  The output is directly saved in a file and not echoed
!       to the screen.
        For Unix the default is "| tee".  The stdout of the compiler is saved
        in a file and echoed to the screen.  If the 'shell' option is "csh" or
        "tcsh" after initializations, the default becomes "|& tee".  If the
***************
*** 6638,6645 ****
        security reasons.
  
                                                *'shellquote'* *'shq'*
! 'shellquote' 'shq'    string  (default: ""; Win32, when 'shell'
!                                       contains "sh" somewhere: "\"")
                        global
        Quoting character(s), put around the command passed to the shell, for
        the "!" and ":!" commands.  The redirection is kept outside of the
--- 6648,6656 ----
        security reasons.
  
                                                *'shellquote'* *'shq'*
! 'shellquote' 'shq'    string  (default: ""; Win32, when 'shell' does not
!                                contain powershell but contains "sh"
!                                somewhere: "\"")
                        global
        Quoting character(s), put around the command passed to the shell, for
        the "!" and ":!" commands.  The redirection is kept outside of the
***************
*** 6654,6660 ****
        security reasons.
  
                                                *'shellredir'* *'srr'*
! 'shellredir' 'srr'    string  (default ">", ">&" or ">%s 2>&1")
                        global
        String to be used to put the output of a filter command in a temporary
        file.  See also |:!|.  See |option-backslash| about including spaces
--- 6665,6672 ----
        security reasons.
  
                                                *'shellredir'* *'srr'*
! 'shellredir' 'srr'    string  (default ">", ">&", ">%s 2>&1", or
!                                "2>&1 | Out-File -Encoding default")
                        global
        String to be used to put the output of a filter command in a temporary
        file.  See also |:!|.  See |option-backslash| about including spaces
***************
*** 6667,6674 ****
        'shell' option is "sh", "ksh", "mksh", "pdksh", "zsh", "zsh-beta",
        "bash" or "fish", the default becomes ">%s 2>&1".  This means that
        stderr is also included.  For Win32, the Unix checks are done and
!       additionally "cmd" is checked for, which makes the default ">%s 2>&1".
!       Also, the same names with ".exe" appended are checked for.
        The initialization of this option is done after reading the ".vimrc"
        and the other initializations, so that when the 'shell' option is set
        there, the 'shellredir' option changes automatically unless it was
--- 6679,6688 ----
        'shell' option is "sh", "ksh", "mksh", "pdksh", "zsh", "zsh-beta",
        "bash" or "fish", the default becomes ">%s 2>&1".  This means that
        stderr is also included.  For Win32, the Unix checks are done and
!       additionally "cmd" is checked for, which makes the default ">%s 2>&1",
!       and "powershell" is checked for which makes the default
!       "2>&1 | Out-File -Encoding default".  Also, the same names with ".exe"
!       appended are checked for.
        The initialization of this option is done after reading the ".vimrc"
        and the other initializations, so that when the 'shell' option is set
        there, the 'shellredir' option changes automatically unless it was
***************
*** 6683,6691 ****
                        global
                        {only for MS-Windows}
        When set, a forward slash is used when expanding file names.  This is
!       useful when a Unix-like shell is used instead of cmd.exe.  Backward
!       slashes can still be typed, but they are changed to forward slashes by
!       Vim.
        Note that setting or resetting this option has no effect for some
        existing file names, thus this option needs to be set before opening
        any file for best results.  This might change in the future.
--- 6697,6705 ----
                        global
                        {only for MS-Windows}
        When set, a forward slash is used when expanding file names.  This is
!       useful when a Unix-like shell is used instead of cmd.exe or
!       powershell.exe.  Backward slashes can still be typed, but they are
!       changed to forward slashes by Vim.
        Note that setting or resetting this option has no effect for some
        existing file names, thus this option needs to be set before opening
        any file for best results.  This might change in the future.
***************
*** 6739,6744 ****
--- 6753,6760 ----
                                                *'shellxquote'* *'sxq'*
  'shellxquote' 'sxq'   string  (default: "";
                                        for Win32, when 'shell' is cmd.exe: "("
+                                       for Win32, when 'shell' is
+                                       powershell.exe: "\""
                                        for Win32, when 'shell' contains "sh"
                                        somewhere: "\""
                                        for Unix, when using system(): "\"")
***************
*** 6751,6761 ****
        then ')"' is appended.
        When the value is '(' then also see 'shellxescape'.
        This is an empty string by default on most systems, but is known to be
!       useful for on Win32 version, either for cmd.exe which automatically
!       strips off the first and last quote on a command, or 3rd-party shells
!       such as the MKS Korn Shell or bash, where it should be "\"".  The
!       default is adjusted according the value of 'shell', to reduce the need
!       to set this option by the user.  See |dos-shell|.
        This option cannot be set from a |modeline| or in the |sandbox|, for
        security reasons.
  
--- 6767,6778 ----
        then ')"' is appended.
        When the value is '(' then also see 'shellxescape'.
        This is an empty string by default on most systems, but is known to be
!       useful for on Win32 version, either for cmd.exe and powershell.exe
!       which automatically strips off the first and last quote on a command,
!       or 3rd-party shells such as the MKS Korn Shell or bash, where it
!       should be "\"".  The default is adjusted according the value of
!       'shell', to reduce the need to set this option by the user.  See
!       |dos-shell|.
        This option cannot be set from a |modeline| or in the |sandbox|, for
        security reasons.
  
*** ../vim-8.2.3070/runtime/doc/os_dos.txt      2021-01-31 17:02:06.258490157 
+0100
--- runtime/doc/os_dos.txt      2021-06-28 20:42:51.932592764 +0200
***************
*** 17,22 ****
--- 17,23 ----
  7. Interrupting                       |dos-CTRL-Break|
  8. Temp files                 |dos-temp-files|
  9. Shell option default               |dos-shell|
+ 10. PowerShell                        |dos-powershell|
  
  ==============================================================================
  1. File locations                                     *dos-locations*
***************
*** 297,304 ****
        <shell> -c "command name >file"
  For DOS 32 bit, DJGPP does this internally somehow.
  
! When starting up, Vim checks for the presence of "sh" anywhere in the 'shell'
! option.  If it is present, Vim sets the 'shellcmdflag' and 'shellquote' or
! 'shellxquote' options will be set as described above.
  
   vim:tw=78:ts=8:noet:ft=help:norl:
--- 298,343 ----
        <shell> -c "command name >file"
  For DOS 32 bit, DJGPP does this internally somehow.
  
! When starting up, if Vim does not recognise a standard Windows shell it checks
! for the presence of "sh" anywhere in the 'shell' option.  If it is present,
! Vim sets the 'shellcmdflag' and 'shellquote' or 'shellxquote' options will be
! set as described above.
! 
! ==============================================================================
! 10. PowerShell                                                *dos-powershell*
! 
! Vim also supports Windows PowerShell.  If 'shell' has been set to
! "powershell.exe" at startup then VIM sets 'shellcmdflag', 'shellxquote',
! 'shellpipe', and 'shellredir' options to the following values:
! 
! 'shellcmdflag'        -Command
! 'shellxquote' "
! 'shellpipe'   2>&1 | Out-File -Encoding default
! 'shellredir'  2>&1 | Out-File -Encoding default
! 
! If you find that PowerShell commands are taking a long time to run then try
! setting 'shellcmdflag' to "-NoProfile -Command".  Note this will prevent any
! PowerShell environment setup by the profile from taking place.
! 
! If you have problems running PowerShell scripts through the 'shell' then try
! setting 'shellcmdflag' to "-ExecutionPolicy RemoteSigned -Command".  See
! online Windows documentation for more information on PowerShell Execution
! Policy settings.
! 
! The 'shellpipe' and 'shellredir' option values re-encode the UTF-16le output
! from Windows PowerShell to your currently configured console codepage.  The
! output can be forced into a different encoding by changing "default" to one of
! the following:
! 
!       unicode          - UTF-16le (default output from PowerShell 5.1)
!       bigendianunicode - UTF-16
!       utf8             - UTF-8
!       utf7             - UTF-7 (no-BOM)
!       utf32            - UTF-32
!       ascii            - 7-bit ASCII character set
!       default          - System's active code page (typically ANSI)
!       oem              - System's current OEM code page
! 
! Note Multi-byte Unicode encodings include a leading BOM.
  
   vim:tw=78:ts=8:noet:ft=help:norl:
*** ../vim-8.2.3070/src/fileio.c        2021-06-27 14:08:17.568112117 +0200
--- src/fileio.c        2021-06-28 20:42:51.932592764 +0200
***************
*** 5245,5253 ****
  
      // Backslashes in a temp file name cause problems when filtering with
      // "sh".  NOTE: This also checks 'shellcmdflag' to help those people who
!     // didn't set 'shellslash'.
      retval = utf16_to_enc(itmp, NULL);
!     if (*p_shcf == '-' || p_ssl)
        for (p = retval; *p; ++p)
            if (*p == '\\')
                *p = '/';
--- 5245,5254 ----
  
      // Backslashes in a temp file name cause problems when filtering with
      // "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)
        for (p = retval; *p; ++p)
            if (*p == '\\')
                *p = '/';
*** ../vim-8.2.3070/src/misc2.c 2021-06-02 13:28:11.435120452 +0200
--- src/misc2.c 2021-06-28 20:42:51.932592764 +0200
***************
*** 1396,1402 ****
  /*
   * Escape "string" for use as a shell argument with system().
   * This uses single quotes, except when we know we need to use double quotes
!  * (MS-DOS and MS-Windows without 'shellslash' set).
   * Escape a newline, depending on the 'shell' option.
   * When "do_special" is TRUE also replace "!", "%", "#" and things starting
   * with "<" like "<cfile>".
--- 1396,1404 ----
  /*
   * Escape "string" for use as a shell argument with system().
   * This uses single quotes, except when we know we need to use double quotes
!  * (MS-DOS and MS-Windows not using PowerShell and without 'shellslash' set).
!  * PowerShell also uses a novel escaping for enclosed single quotes - double
!  * them up.
   * Escape a newline, depending on the 'shell' option.
   * When "do_special" is TRUE also replace "!", "%", "#" and things starting
   * with "<" like "<cfile>".
***************
*** 1412,1417 ****
--- 1414,1423 ----
      char_u    *escaped_string;
      int               l;
      int               csh_like;
+ # ifdef MSWIN
+     int               powershell;
+     int               double_quotes;
+ # endif
  
      // Only csh and similar shells expand '!' within single quotes.  For sh 
and
      // the like we must not put a backslash before it, it will be taken
***************
*** 1419,1430 ****
      // Csh also needs to have "\n" escaped twice when do_special is set.
      csh_like = csh_like_shell();
  
      // First count the number of extra bytes required.
      length = (unsigned)STRLEN(string) + 3;  // two quotes and a trailing NUL
      for (p = string; *p != NUL; MB_PTR_ADV(p))
      {
  # ifdef MSWIN
!       if (!p_ssl)
        {
            if (*p == '"')
                ++length;               // " -> ""
--- 1425,1442 ----
      // Csh also needs to have "\n" escaped twice when do_special is set.
      csh_like = csh_like_shell();
  
+ # ifdef MSWIN
+     // PowerShell only accepts single quotes so override p_ssl.
+     powershell = strstr((char *)gettail(p_sh), "powershell") != NULL;
+     double_quotes = !powershell && !p_ssl;
+ # endif
+ 
      // First count the number of extra bytes required.
      length = (unsigned)STRLEN(string) + 3;  // two quotes and a trailing NUL
      for (p = string; *p != NUL; MB_PTR_ADV(p))
      {
  # ifdef MSWIN
!       if (double_quotes)
        {
            if (*p == '"')
                ++length;               // " -> ""
***************
*** 1432,1438 ****
        else
  # endif
        if (*p == '\'')
!           length += 3;                // ' => '\''
        if ((*p == '\n' && (csh_like || do_newline))
                || (*p == '!' && (csh_like || do_special)))
        {
--- 1444,1457 ----
        else
  # endif
        if (*p == '\'')
!       {
! # ifdef MSWIN
!           if (powershell)
!               length +=2;             // ' => ''
!           else
! # endif
!               length += 3;            // ' => '\''
!       }
        if ((*p == '\n' && (csh_like || do_newline))
                || (*p == '!' && (csh_like || do_special)))
        {
***************
*** 1455,1461 ****
  
        // add opening quote
  # ifdef MSWIN
!       if (!p_ssl)
            *d++ = '"';
        else
  # endif
--- 1474,1480 ----
  
        // add opening quote
  # ifdef MSWIN
!       if (double_quotes)
            *d++ = '"';
        else
  # endif
***************
*** 1464,1470 ****
        for (p = string; *p != NUL; )
        {
  # ifdef MSWIN
!           if (!p_ssl)
            {
                if (*p == '"')
                {
--- 1483,1489 ----
        for (p = string; *p != NUL; )
        {
  # ifdef MSWIN
!           if (double_quotes)
            {
                if (*p == '"')
                {
***************
*** 1478,1487 ****
  # endif
            if (*p == '\'')
            {
!               *d++ = '\'';
!               *d++ = '\\';
!               *d++ = '\'';
!               *d++ = '\'';
                ++p;
                continue;
            }
--- 1497,1516 ----
  # endif
            if (*p == '\'')
            {
! # ifdef MSWIN
!               if (powershell)
!               {
!                   *d++ = '\'';
!                   *d++ = '\'';
!               }
!               else
! # endif
!               {
!                   *d++ = '\'';
!                   *d++ = '\\';
!                   *d++ = '\'';
!                   *d++ = '\'';
!               }
                ++p;
                continue;
            }
***************
*** 1507,1513 ****
  
        // add terminating quote and finish with a NUL
  # ifdef MSWIN
!       if (!p_ssl)
            *d++ = '"';
        else
  # endif
--- 1536,1542 ----
  
        // add terminating quote and finish with a NUL
  # ifdef MSWIN
!       if (double_quotes)
            *d++ = '"';
        else
  # endif
*** ../vim-8.2.3070/src/option.c        2021-06-20 14:01:25.984924607 +0200
--- src/option.c        2021-06-28 20:42:51.936592752 +0200
***************
*** 932,937 ****
--- 932,958 ----
                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,994 ****
       * 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.
       */
!     if (strstr((char *)gettail(p_sh), "sh") != NULL)
      {
        int     idx3;
  
--- 1005,1039 ----
       * 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 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), "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;
  
*** ../vim-8.2.3070/src/os_win32.c      2021-06-08 18:32:31.499453482 +0200
--- src/os_win32.c      2021-06-28 20:42:51.936592752 +0200
***************
*** 2142,2148 ****
        return FALSE;
  
      // Using the name directly when a Unix-shell like 'shell'.
!     if (strstr((char *)gettail(p_sh), "sh") != NULL)
        noext = TRUE;
  
      if (use_pathext)
--- 2142,2149 ----
        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)
        noext = TRUE;
  
      if (use_pathext)
*** ../vim-8.2.3070/src/testdir/test_shell.vim  2021-06-27 22:09:56.032999658 
+0200
--- src/testdir/test_shell.vim  2021-06-28 20:42:51.936592752 +0200
***************
*** 24,31 ****
    if has('win32')
      let shells += [['cmd', '/c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', ''],
            \ ['cmd.exe', '/c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '('],
!           \ ['powershell.exe', '-c', '>', '', '>', '"&|<>()@^', '"'],
!           \ ['powershell', '-c', '>', '', '>', '"&|<>()@^', '"'],
            \ ['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', '"&|<>()@^', '"'],
--- 24,33 ----
    if has('win32')
      let shells += [['cmd', '/c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', ''],
            \ ['cmd.exe', '/c', '>%s 2>&1', '', '>%s 2>&1', '"&|<>()@^', '('],
!           \ ['powershell.exe', '-Command', '2>&1 | Out-File -Encoding 
default',
!           \           '', '2>&1 | Out-File -Encoding default', '"&|<>()@^', 
'"'],
!           \ ['powershell', '-Command', '2>&1 | Out-File -Encoding default', 
'',
!           \               '2>&1 | Out-File -Encoding default', '"&|<>()@^', 
'"'],
            \ ['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', '"&|<>()@^', '"'],
***************
*** 58,63 ****
--- 60,68 ----
      if e[0] =~# '.*csh$' || e[0] =~# '.*csh.exe$'
        let str1 = "'cmd \"arg1\" '\\''arg2'\\'' \\!%#'"
        let str2 = "'cmd \"arg1\" '\\''arg2'\\'' \\\\!\\%\\#'"
+     elseif e[0] =~# '.*powershell$' || e[0] =~# '.*powershell.exe$'
+       let str1 = "'cmd \"arg1\" ''arg2'' !%#'"
+       let str2 = "'cmd \"arg1\" ''arg2'' \\!\\%\\#'"
      else
        let str1 = "'cmd \"arg1\" '\\''arg2'\\'' !%#'"
        let str2 = "'cmd \"arg1\" '\\''arg2'\\'' \\!\\%\\#'"
***************
*** 135,140 ****
--- 140,167 ----
    let &shell = save_shell
  endfunc
  
+ " Test for 'shellslash'
+ func Test_shellslash()
+   CheckOption shellslash
+   let save_shellslash = &shellslash
+   " The shell and cmdflag, and expected slash in tempname with shellslash set 
or
+   " unset.  The assert checks the file separator before the leafname.
+   " ".*\\\\[^\\\\]*$"
+   let shells = [['cmd', '/c', '\\', '/'],
+         \ ['powershell', '-Command', '\\', '/'],
+         \ ['sh', '-c', '/', '/']]
+   for e in shells
+     exe 'set shell=' .. e[0] .. ' | set shellcmdflag=' .. e[1]
+     set noshellslash
+     let file = tempname()
+     call assert_match('^.\+' .. e[2] .. '[^' .. e[2] .. ']\+$', file, e[0] .. 
' ' .. e[1] .. ' nossl')
+     set shellslash
+     let file = tempname()
+     call assert_match('^.\+' .. e[3] .. '[^' .. e[3] .. ']\+$', file, e[0] .. 
' ' .. e[1] .. ' ssl')
+   endfor
+   let &shellslash = save_shellslash
+ endfunc
+ 
  " Test for 'shellxquote'
  func Test_shellxquote()
    CheckUnix
*** ../vim-8.2.3070/src/version.c       2021-06-27 22:09:56.032999658 +0200
--- src/version.c       2021-06-28 20:51:58.771065358 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3071,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
43. You tell the kids they can't use the computer because "Daddy's got work to
    do" and you don't even have a job.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202106281854.15SIsdlt972714%40masaka.moolenaar.net.

Raspunde prin e-mail lui