Files
neovim/runtime/doc
Justin M. Keyes 01721aaa66 Merge #19438 from 3N4N/fix/pwsh
Reverts #16271
Fixs #15913

Problem:
Since #16271, `make_filter_cmd` uses `Start-Process` cmdlet to execute the user
provided shell command for `:%!`. `Start-Process` requires the command to be
split into the shell command and its arguments. This was implemented in #19268
by parsing (splitting the user-provided command at the first space) which didn't
handle cases such as --
  - commands with escaped space in their filepath
  - quoted commands with space in their filepath

Solution: Use piping.

The total shell command formats (excluding noise of unimportant parameters):

1. Before #16271
    ```powershell
    pwsh -C "(shell_cmd) < tmp.in | 2>&1 Out-File -Encoding UTF8 <tmp.out>"
    # not how powershell commands work
    ```
2. Since #16271
    ```powershell
    pwsh -C "Start-Process shell_cmd -RedirectStandardInput <tmp.in> -RedirectStandardOutput <tmp.out>"
    # doesn't handle executable path with space in it
    # doesn't write error to <tmp.out>
    ```
3. This PR
    ```powershell
    pwsh -C "& { Get-Content <tmp.in> | & 'path\with space\to\shell_cmd.exe' arg1 arg2 } 2>&1 | Out-File -Encoding UTF8 <tmp.out>"
    # also works with forward slash in the filepath
    # also works with double quotes around shell command
    ```

After this PR, the user can use the following formats:

    :%!c:\Program` Files\Git\usr\bin\sort.exe
    :%!'c:\Program Files\Git\usr\bin\sort.exe'
    :%!"c:\Program Files\Git\usr\bin\sort.exe"
    :%!"c:\Program` Files\Git\usr\bin\sort.exe"

They can even chain different commands:

    :%!"c:\Program` Files\Git\usr\bin\sort.exe" | sort.exe -r

But if they want to call a stringed executable path, they have to provide the
Invoke-Command operator (&). In fact, the first stringed executable path also
needs this & operator, but this PR adds that behind the scene.

    :%!"c:\Program` Files\Git\usr\bin\sort.exe" | sort.exe -r | & 'c:\Program Files\Git\usr\bin\sort.exe'

## What this PR solves

- Having to parse the user-provided bang ex-command (for splitting into shell
  cmd and its args).
- Removes a lot of human-unreadable `#ifdef` blocks.
- Accepting escaped spaces in executable path.
- Accepting quoted string of executable path.
- Redirects error and exception to tmp.out (exception for when `wrong_cmd.exe
  not found`)

## What this PR doesn't solve

- Handling wrongly escaped path to executable, which the user may pass because
  of cmdline tab-completion. #18592

## Edge cases
- (Not handled) If the user themself provides the `&` sign (means `call
  this.exe` in powershell)
- (Not handled) Use `-Encoding utf8` parameter for `Get-Content`?
- (Handled) Doesn't write to tmp.out if shell command is not found.
    - fix: use anonymous function (`{wrong_cmd.exe}`).

## Changes other than `make_filter_cmd()` function

- Encoding for piping to external executables. See BOM-less UTF8:
  https://github.com/PowerShell/PowerShell/issues/4681
2022-10-01 17:29:15 -04:00
..
2022-09-18 15:20:20 +02:00
2022-09-26 17:43:23 +08:00
2022-02-27 11:56:30 +01:00
2022-02-27 11:56:30 +01:00
2022-09-30 09:53:52 +02:00
2021-09-10 08:48:27 +02:00
2022-02-27 11:56:30 +01:00
2018-10-29 09:55:07 +01:00
2022-09-25 16:58:27 -07:00
2022-01-11 14:14:17 +01:00
2022-02-27 11:56:30 +01:00
2022-08-25 00:49:33 +02:00
2022-09-18 15:20:20 +02:00
2021-09-09 00:37:59 -07:00
2022-01-04 11:07:40 -07:00
2022-09-30 09:53:52 +02:00
2018-08-25 15:25:49 +02:00
2021-04-28 21:29:57 -04:00
2022-09-28 12:48:36 +02:00
2022-03-25 19:57:59 +01:00
2022-09-28 12:48:36 +02:00
2019-03-26 19:55:33 +01:00
2018-10-29 09:55:07 +01:00
2022-09-26 17:43:23 +08:00
2022-01-29 23:15:22 +00:00
2018-10-29 09:55:07 +01:00
2018-10-29 09:55:07 +01:00
2015-08-15 15:25:30 -03:00
2021-11-17 10:02:59 +01:00
2022-09-26 17:43:23 +08:00
2019-03-26 19:55:33 +01:00
2022-03-17 13:21:24 +08:00
2022-09-28 12:48:36 +02:00
2021-09-10 08:48:27 +02:00
2022-02-27 11:56:30 +01:00
2022-09-18 15:20:20 +02:00
2022-09-30 09:53:52 +02:00
2022-09-26 17:43:23 +08:00
2022-09-10 14:54:13 +02:00
2022-01-29 23:15:22 +00:00
2022-02-27 11:56:30 +01:00
2022-07-26 11:26:23 +02:00
2022-09-26 17:43:23 +08:00
2021-04-27 09:21:30 -04:00
2021-05-02 13:00:38 -04:00
2021-05-01 23:19:57 -04:00
2022-06-04 11:56:36 +08:00
2022-07-31 16:46:38 +08:00
2021-09-08 07:24:12 -07:00
2021-05-01 22:29:02 -04:00
2021-05-02 12:53:49 -04:00
2021-11-22 10:53:57 +01:00
2022-09-26 17:43:23 +08:00
2021-05-01 22:29:03 -04:00
2021-04-27 09:21:33 -04:00
2018-10-29 10:01:44 +01:00
2021-04-29 09:27:19 -04:00
2018-10-29 10:01:44 +01:00
2022-03-20 10:48:10 +01:00
2021-04-29 20:42:16 -04:00
2021-04-29 20:42:16 -04:00
2018-10-29 10:01:44 +01:00
2022-06-23 15:57:51 +02:00
2019-03-26 19:55:33 +01:00
2021-04-27 09:21:34 -04:00
2021-05-01 23:19:57 -04:00