Skip to content

fix(windows): auto-detect pwsh/powershell (Fixes #301)#302

Merged
brianhuster merged 1 commit intobrianhuster:mainfrom
sarahyack:fix-windows-pwsh
May 22, 2025
Merged

fix(windows): auto-detect pwsh/powershell (Fixes #301)#302
brianhuster merged 1 commit intobrianhuster:mainfrom
sarahyack:fix-windows-pwsh

Conversation

@sarahyack
Copy link
Copy Markdown
Contributor

Issue

The default shell command selection for windows was simply "pwsh", as this is only applicable for Powershell Core (6/7) shipped with Windows 11, it is not applicable for Windows 10, as it usually ships with Powershell 5.1, which does not have the pwsh command built-in, and instead launches with the command powershell.

Fixes #301

Fix

Changed the windows shell selection part of utils.term_cmd & utils.await_term_cmd to use a new picker function pick_powershell(), that determines which command vim detects is available with vim.fn.executable(), with a preference towards the newer pwsh, and a fallback to powershell.

Testing

I do not have a Windows 11 machine or VM, so only tested on a Windows 10 machine, but the error mentioned in #301 no longer occurs with the new changes, and :LivePreview start works as expected. No changes to previous functionality for windows users should occur besides adding support for Windows 10, thus I expect everything should work fine on a Windows 11 machine.

Happy to tweak based on feedback!

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pull request! We appreciate your contribution. Please ensure that your changes are well documented and tested, and are formatted as noexpandtab.

Comment thread lua/livepreview/utils.lua Outdated
@sarahyack
Copy link
Copy Markdown
Contributor Author

Please take a look and let me know if there are any more issues!

@sarahyack
Copy link
Copy Markdown
Contributor Author

Heads Up (Unrelated to this Fix):

While testing, I noticed that the plugin was failing to initialize a server for a HTML file I was trying to open. I had previously with the initial tests opened a Markdown file and not an HTML file, so I have no context in regards to whether it was broken then too, but as of right now the server is failing to start for HTML files. It will, however start for a Markdown file, though it only works the first time you open the server, after which even if you kill the port connection (whether using built-in :LivePreview close or using PowerShell), it will still initialize the process, but it'll get stuck in an endless loading loop. Errors suggest that it is unable to overwrite the port instance as it is "read-only or constant" in the case of the Markdown issue, and that when trying to preview a HTML file the value of server is nil. I've determined that I did not introduce these issues, and I've checked compatibility for what PowerShell commands I could find to make sure it's compatible with PowerShell 5.1 as well, and there are no issues in that regard.

Let me know if you would like me to file bug reports related to the issues outlined above, and I'd be happy to oblige! Please note, however, the scope of these issues falls outside of my experience, and I would be unlikely to be able to resolve them.

Comment thread lua/livepreview/utils.lua Outdated
@brianhuster
Copy link
Copy Markdown
Owner

Yes, you can open a bug report with reproduce steps

@sarahyack
Copy link
Copy Markdown
Contributor Author

Does anything require change for this PR?

Comment thread lua/livepreview/utils.lua
@brianhuster
Copy link
Copy Markdown
Owner

Can you please rebase it?

@sarahyack
Copy link
Copy Markdown
Contributor Author

Can you please rebase it?

Never used rebase before, so not sure exactly how well I did, but is that satisfactory?

@brianhuster
Copy link
Copy Markdown
Owner

brianhuster commented May 21, 2025

No, I mean you should make your PR contains only 1 commit

@sarahyack
Copy link
Copy Markdown
Contributor Author

No, I mean you should make your PR contains only 1 commit

Why not squash & merge? I'm not sure how I could do that. I could simply erase the history, I suppose and rebase to the beginning, but wouldn't a squash make more sense?

@brianhuster
Copy link
Copy Markdown
Owner

Yes, I mean squash

@sarahyack
Copy link
Copy Markdown
Contributor Author

Yes, I mean squash

That's as good as I can get. I tried to rebase it to the first commit hash in the git log, but it still says 4 commits. I thought the squash happens when the merge is accepted, and done as a "Squash & merge"? My git knowledge is limited, and I'm not entirely sure what else I can do to "squash".

@brianhuster
Copy link
Copy Markdown
Owner

Use command git rebase -i HEAD~4

@sarahyack
Copy link
Copy Markdown
Contributor Author

Use command git rebase -i HEAD~4

Thank you, how's that?

@brianhuster
Copy link
Copy Markdown
Owner

LGTM

@brianhuster brianhuster merged commit 0b77181 into brianhuster:main May 22, 2025
1 check passed
@sarahyack sarahyack deleted the fix-windows-pwsh branch May 22, 2025 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: "no such file or directory: 'pwsh'" on Windows

2 participants