From 7fe6ceae7ff8e81664dd133c71caa169771f3570 Mon Sep 17 00:00:00 2001 From: pm100 Date: Sun, 9 Apr 2023 17:07:32 -0700 Subject: [PATCH 1/2] make vim work --- src/components/externaleditor.rs | 38 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/components/externaleditor.rs b/src/components/externaleditor.rs index 3c9c918602..9ace9ddea9 100644 --- a/src/components/externaleditor.rs +++ b/src/components/externaleditor.rs @@ -112,11 +112,41 @@ impl ExternalEditorComponent { args.push(path.as_os_str()); - Command::new(command.clone()) - .current_dir(work_dir) + let exec_result = Command::new(command.clone()) + .current_dir(work_dir.clone()) .args(args) - .status() - .map_err(|e| anyhow!("\"{}\": {}", command, e))?; + .status(); + + if cfg!(windows) { + // if command failed to run on windows retry as a batch file (.bat, .cmd,...) + if exec_result.is_err() { + let cmd_string = + format!("/C {} {}", command, path.display()); + let exec_result2 = + Command::new("cmd").arg(cmd_string).status(); + + match exec_result2 { + // failed to start (unlikely as cmd would have to be missing) + Err(e) => bail!("\"{}\": {}", command, e), + + // ran, did it complete OK? + Ok(stat) => { + // no result is treated as arbitrary failure code of 99 + let code = stat.code().unwrap_or(99); + if code != 0 { + bail!( + "\"{}\": cmd.exe returned {}", + command, + code + ) + } + } + }; + } + } else { + exec_result + .map_err(|e| anyhow!("\"{}\": {}", command, e))?; + } Ok(()) } From 90499d5d4d3b28271ab03f8eff31cc21c5df4a3c Mon Sep 17 00:00:00 2001 From: pm100 Date: Sun, 9 Apr 2023 17:46:49 -0700 Subject: [PATCH 2/2] forgot clippy --- src/components/externaleditor.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/externaleditor.rs b/src/components/externaleditor.rs index 9ace9ddea9..00565cdabc 100644 --- a/src/components/externaleditor.rs +++ b/src/components/externaleditor.rs @@ -122,8 +122,10 @@ impl ExternalEditorComponent { if exec_result.is_err() { let cmd_string = format!("/C {} {}", command, path.display()); - let exec_result2 = - Command::new("cmd").arg(cmd_string).status(); + let exec_result2 = Command::new("cmd") + .current_dir(work_dir) + .arg(cmd_string) + .status(); match exec_result2 { // failed to start (unlikely as cmd would have to be missing)