Repository navigation
allow ps1 files to be executed without pwsh/powershell -c file.ps1 - #14379
Conversation
|
I'd love to see this also require the script to (1) be on the search path or (2) require an absolute or relative path (e.g. |
|
The implementation works similar to how the nushell script functionality works on Windows. I'd prefer to leave it like it is for now. However, it should still work like |
WindSoilder
left a comment
There was a problem hiding this comment.
Thanks! I like the idea!
Do you think it's possible to add a windows test for it?
@WindSoilder I'm not familiar with these type of tests and can't get it to work. Maybe you'll have some insight. I added this test below to nushell\crates\nu-command\tests\commands\run_external.rs #[cfg(windows)]
#[test]
fn can_run_ps1_files() {
use nu_test_support::fs::Stub::FileWithContent;
Playground::setup("run a Windows ps file", |dirs, sandbox| {
sandbox.with_files(&[FileWithContent(
"foo.ps1",
r#"
Write-Host Hello World
"#,
)]);
let actual = nu!(cwd: dirs.test(), pipeline("foo.ps1"));
assert!(actual.out.contains("Hello World"));
});
}Then it gives this error, which is a powershell error that shows up when it can't find a file. I'm not sure why it's not finding my foo.ps1 file because I the test does the same as the foo.bat and foo.cmd. |
|
I think I may have figured it out. For some reason, I can't have a path with spaces in it and i have to provide the full path to the ps1 file in the test. I don't understand why but it seems to be passing now. |
|
I tried to make it work on non-windows where pwsh existed, but it seems like too much trouble for now. I'll settle for Windows only atm. |
Co-authored-by: Wind <[email protected]>
|
Is it possible to configure this to use |
|
I chose to make it powershell since it is installed on every modern Windows installation, pwsh is not. There could be a config point written/added to allow this but there currently is not. |
|
Yes, I think powershell is the correct default, but I would like it to be configurable as pwsh is basically just better (when it's installed!) I don't know the codebase, so I'm not sure if I could write a PR myself to make this configurable, unfortunately :-( |
Description
This PR allows nushell to run powershell scripts easier. You can already do

powershell -c script.ps1but this PR takes it a step further by doing thepowershell -cpart for you. So, if you have script.ps1 you can execute it by running it in the command position of the repl.or once it's in json, just consume it with nushell.

User-Facing Changes
Easier to run powershell scripts. It should work on Windows with powershell.exe and mac/linux if you have pwsh.exe installed. More testing is needed.
Tests + Formatting
After Submitting