MiguelBarro / setpwsh

vim plugin for powershell integration
Apache License 2.0
2 stars 0 forks source link

Merge into upstream #1

Open Konfekt opened 2 months ago

Konfekt commented 2 months ago

Thank you for digging into this. I am not sure to what extent Powershell as &shell is currently supported by Vim so that maybe workarounds such as https://github.com/janlazo/dotvim8/blob/9cad83eecc2b0cb9c7bb6485f601982048af9254/shared.vim#L215 and https://stackoverflow.com/a/27499996/3528522 have become obsolete, but it would be helpful if there is official documentation and support of it.

MiguelBarro commented 2 months ago

The pity is that there is no workaround. I've been working with vim + powershell for years (in windows) and since the very begining I tried to fine tune the vim options, as the references you quoted, without success.

The vim docs hints some powershell configs but all fail in windows to provide the expected outcome, that is, write commands as in a terminal (without escaping them).

After much tampering I discovered it was windows' fault. Unlike posix-like OS it uses convoluted rules to translate command line arguments to the binaries. My educated guess is that they keep them for backward compatibility. Powershell and pwsh binaries suffer them.

Powershell team was aware of this and introduced their own workaround: a parameter -EncodedCommand that accepts the command line encoded in base64 to avoid the necessity of escaping any character. This comes handy, for example, in windows Dockerfiles where each line is delivered to the shell and suffers the very same issue.

I thought for a while that, introduce a new vim option to allow feeding the shell with base64 encoded commands, was the way to go. But eventually, I realized that many applications workaround this by querying the actual command line using GetCommandLine windows' API. We can do the same if we replace the plain shell call with a call to a special shell script that does precisely that. That is the main idea behind the plugin.

Konfekt commented 2 months ago

Yes, understood. Thank you very much. Your solution is great.

There's a tools folder https://github.com/vim/vim/tree/ddf28f23e55afba9967acca7969252d7a36fd73c/runtime/tools in the Vim distribution where the scripts could be placed, and then added to %PATH% in Win32, similar to https://github.com/chrisbra/vpager/blob/d18bf235bacc209946d1d01c03ca6f85b1c0fd2c/plugin/vpager.vim#L29C1-L40C17 (or how your plug-in does it); then the setup of powershell can be adapted, once your scripts are assured to be in %PATH%. This could be made optional by a g:pwsh_encoded_commands toggle.