diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 6cf7faf3..4e7e9796 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -1006,8 +1006,39 @@ pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> { Ok(()) } +enum Hx { + Helix(PathBuf), + HxHexdump, +} + +impl Hx { + fn helix(self) -> Result { + match self { + Hx::Helix(hx) => Ok(hx), + Hx::HxHexdump => { + Err(SkipStep("Command `hx` probably points to hx (hexdump alternative)".to_string()).into()) + } + } + } +} + +fn get_hx(ctx: &ExecutionContext) -> Result { + let hx = require("hx")?; + + // Check if `hx --help` mentions "helix". Helix does, hx (hexdump alternative) doesn't. + let output = ctx.run_type().execute(&hx).arg("--help").output_checked()?; + + if String::from_utf8(output.stdout)?.contains("helix") { + debug!("Detected `hx` as Helix"); + Ok(Hx::Helix(hx)) + } else { + debug!("Detected `hx` as hx (hexdump alternative)"); + Ok(Hx::HxHexdump) + } +} + pub fn run_helix_grammars(ctx: &ExecutionContext) -> Result<()> { - let helix = require("helix").or(require("hx"))?; + let helix = require("helix").or(get_hx(ctx)?.helix())?; print_separator("Helix");