diff --git a/src/lib.rs b/src/lib.rs index b633a1d65d..453cb511a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,6 +42,7 @@ pub(crate) use { expression::Expression, format_string_part::FormatStringPart, fragment::Fragment, + fs::File, function::Function, interpreter::Interpreter, invocation::Invocation, diff --git a/src/recipe.rs b/src/recipe.rs index daa63c910c..751ead13bd 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -467,10 +467,24 @@ impl<'src, D> Recipe<'src, D> { eprintln!("{}", config.color.doc().stderr().paint(&script)); } - fs::write(&path, script).map_err(|error| Error::TempdirIo { - recipe: self.name(), - io_error: error, - })?; + let interpreter = match &executor { + Executor::Shebang(shebang) => shebang.interpreter, + Executor::Command(command) => command.command.as_str(), + }; + let preamble = match interpreter.to_lowercase().as_str() { + "powershell" | "powershell.exe" => "\u{FEFF}", + _ => "", + }; + + File::create(&path) + .and_then(|mut f| { + f.write_all(preamble.as_ref())?; + f.write_all(script.as_ref()) + }) + .map_err(|error| Error::TempdirIo { + recipe: self.name(), + io_error: error, + })?; let mut command = executor.command( config,