From d398b9f9e107ab692f4b465ea4d953c132e9ae8b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 20 Sep 2026 16:21:57 +0200 Subject: [PATCH 01/21] allow specifying #! inside shell fixes #51 --- CHANGELOG.md | 4 ++++ README.md | 15 +++++++++++-- example-script.sh | 1 + src/script.rs | 57 ++++++++++++++++++++++++++++++++++------------- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c1b845..d3e4fd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +- Support having a `#!` inside a haze script to specify the interperter to use + ## 2.4.1 - Show database location on start diff --git a/README.md b/README.md index d66688b..b05dfe4 100644 --- a/README.md +++ b/README.md @@ -447,8 +447,19 @@ script can be overriden by running the script with ## Nushell scripts -By default, the script contents are executed as a `bash` script, you can instead -execute the script as a `nushell` script by using `.nu` as the file extention. +By default, the script contents are executed as either `bash` script, or `nu` script based on the extension. + +You can overwrite the interpreter used to execute the script by adding an extra `#!` line to the script, for example: + +```bash +#! /usr/bin/env -S haze script +#! haze shell pgsql s3 +#! php -f + shell, + (None, Some("nu")) => vec!["nu".into()], + _ => vec!["bash".into()], }; options.mappings.push( @@ -61,7 +63,10 @@ pub async fn run_script( cloud .exec( docker, - vec![shell.to_string(), target_path.into_string()], + shell + .into_iter() + .chain(once(target_path.into_string())) + .collect(), true, get_forward_env(), ) @@ -74,14 +79,22 @@ pub async fn run_script( Ok(()) } -fn parse_script(script: &str, config: &HazeConfig) -> Result<(CloudOptions, ScriptMode)> { - let (options, mode) = script +#[derive(Debug)] +struct Script { + options: CloudOptions, + mode: ScriptMode, + shell: Option>, +} + +fn parse_script(script: &str, config: &HazeConfig) -> Result